union all 查询后取交集部分

select DISTINCT a.id FROM ( 
(select distinct t.id from tcompany_kpi t where 1 =1 and t.id in (37395,37396,37397,37398 ) and annual_return >= 0.1 and annual_return <= 0.2 ) 
union ALL 
(select distinct t.id from tcompany_kpi t where 1 =1 and t.id in (37395,37396,37397,37398,37399 ) order by profit_ratio desc LIMIT 0,3 ) 
union ALL 
(select distinct t.id from tcompany_kpi t where 1 =1 and t.id in ( 37395,37396,37397,37398 ) and annual_volatility >= 0.1 and annual_volatility <= 0.2 ) ) a 
GROUP BY a.id HAVING COUNT(*) =3

 

posted @ 2023-03-06 16:40  Lux1997  阅读(52)  评论(0)    收藏  举报