MySql联合查询Union

记一条很长的sql,为了方便阅读,我已经加了段落:

 SELECT * FROM (  
 (SELECT 1 AS acheck, s1.id, s1.plan_name, s1.cost_mode, s1.sta_type, s1.cost_type, s1.cost_period_time, s1.cost_period_value, s1.`carrier_operator`,s1.cost_settle_type  
 FROM wo_serviceplan s1  JOIN wo_serviceplan_hotspot sh ON s1.id = sh.serviceplan_id  
 WHERE s1.is_enable = 1 AND sh.hotspot_id = 109 ORDER BY s1.plan_name ASC )  
 UNION ALL  
 (SELECT 2 AS acheck, s2.id, s2.plan_name, s2.cost_mode, s2.sta_type, s2.cost_type, s2.cost_period_time, s2.cost_period_value, s2.`carrier_operator`,s2.cost_settle_type  
 FROM wo_serviceplan s2  
 WHERE s2.is_enable = 1 AND s2.id NOT IN (  SELECT serviceplan_id FROM wo_serviceplan_hotspot WHERE 1=1  AND hotspot_id = 109 ) 
 ORDER BY s2.plan_name ASC ) ) AS s3   ORDER BY s3.acheck ASC, s3.plan_name ASC  LIMIT 0,20

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。