这两句sql语句助我飞上了天
//结果集
SELECT * FROM (SELECT id,name,state,startingtime,endtime FROM zyd_mall_content
WHERE type=2 and status=1 and state=0 ORDER BY startingtime ASC) a UNION SELECT * FROM (SELECT id,name,state,startingtime,endtime FROM zyd_mall_content
WHERE type=2 and status=1 and state=1 ORDER BY endtime DESC) b UNION SELECT * FROM (SELECT id,name,state,startingtime,endtime FROM zyd_mall_content
WHERE type=2 and status=1 and state=2 ORDER BY startingtime DESC) c
//统计 //必须起别名
SELECT COUNT(*) e FROM (SELECT * FROM (SELECT id,name,state,startingtime,endtime FROM zyd_mall_content
WHERE type=2 and status=1 and state=0 ORDER BY startingtime ASC) a UNION SELECT * FROM (SELECT id,name,state,startingtime,endtime FROM zyd_mall_content
WHERE type=2 and status=1 and state=1 ORDER BY endtime DESC) b UNION SELECT * FROM (SELECT id,name,state,startingtime,endtime FROM zyd_mall_content
WHERE type=2 and status=1 and state=2 ORDER BY startingtime DESC) c) as d