IT大拿好:
select count(*) from t_users where operatedate=to_date('2011-02-16 00:00:00','yyyy-mm-dd hh24:mi:ss'); -- 57
select count(*) from t_users where operatedate=to_date('2011-02-15 00:00:00','yyyy-mm-dd hh24:mi:ss'); --38
select count(*) from t_users where operatedate=to_date('2011-02-14 00:00:00','yyyy-mm-dd hh24:mi:ss'); --76如果用union连接查询,
select count(*) from t_users where operatedate=to_date('2011-02-16 00:00:00','yyyy-mm-dd hh24:mi:ss') union
select count(*) from t_users where operatedate=to_date('2011-02-15 00:00:00','yyyy-mm-dd hh24:mi:ss') union
select count(*) from t_users where operatedate=to_date('2011-02-14 00:00:00','yyyy-mm-dd hh24:mi:ss') 结果如下:
38
57
76查询结果会排序,现在怎么设置 可以不让其排序,安装57,38,76来排序,谢谢大家!
select count(*) from t_users where operatedate=to_date('2011-02-16 00:00:00','yyyy-mm-dd hh24:mi:ss'); -- 57
select count(*) from t_users where operatedate=to_date('2011-02-15 00:00:00','yyyy-mm-dd hh24:mi:ss'); --38
select count(*) from t_users where operatedate=to_date('2011-02-14 00:00:00','yyyy-mm-dd hh24:mi:ss'); --76如果用union连接查询,
select count(*) from t_users where operatedate=to_date('2011-02-16 00:00:00','yyyy-mm-dd hh24:mi:ss') union
select count(*) from t_users where operatedate=to_date('2011-02-15 00:00:00','yyyy-mm-dd hh24:mi:ss') union
select count(*) from t_users where operatedate=to_date('2011-02-14 00:00:00','yyyy-mm-dd hh24:mi:ss') 结果如下:
38
57
76查询结果会排序,现在怎么设置 可以不让其排序,安装57,38,76来排序,谢谢大家!
select count(*) as num,2 as display from t_users where operatedate=to_date('2011-02-15 00:00:00','yyyy-mm-dd hh24:mi:ss') union
select count(*) as num,3 as display from t_users where operatedate=to_date('2011-02-14 00:00:00','yyyy-mm-dd hh24:mi:ss')
order by display
从效率上说,UNION ALL 要比UNION快很多,所以,如果可以确认合并的两个结果集中不包含重复的数据的话,那么就使用UNION ALL