zoukankan      html  css  js  c++  java
  • 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 serviceplan s1  JOIN 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 serviceplan s2  
     WHERE s2.is_enable = 1 AND s2.id NOT IN (  SELECT serviceplan_id FROM 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
  • 相关阅读:
    c函数调用过程
    查找匹配行及前后5行
    指向类成员函数的指针
    C++箴言:理解typename的两个含义
    不定参数
    定时器
    unix编译
    sed
    大脑皮层的梦工厂
    静态链接库顺序问题
  • 原文地址:https://www.cnblogs.com/gyhkevin/p/4504193.html
Copyright © 2011-2022 走看看