标签:
记一条很长的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
标签:
原文地址:http://www.cnblogs.com/gyhkevin/p/4504193.html