17,120
社区成员
发帖
与我相关
我的任务
分享
请问我想查询把上面格式改成 A_Type,A_Count
委托 709
磅单 677
实绩 1135
怎么写?谢谢大神!
首先,创建一张存储A_Type的表MS_TYPE:
然后构造出下面的查询结果:
再与MS_TYPE表进行关联就能得到最终结果。整个的sql语句:
select b.A_Type,a.A_Count from (
select 1 as id,count(*) as A_Count from MS_TJQSC01 where TOC>=to_char(sysdate,'YYYY-MM-DD') and tom<to_char(sysdate+1,'YYYY-MM-DD')
union
select 2 ,count(*) from MS_TJQWE01 where TOC>=to_char(sysdate,'YYYY-MM-DD') and tom<to_char(sysdate+1,'YYYY-MM-DD')
union
select 3,count(*) from MS_TJQWE02 where TOC>=to_char(sysdate,'YYYY-MM-DD') and tom<to_char(sysdate+1,'YYYY-MM-DD')
) a, MS_TYPE b where a.id=b.A_Id
我没有装Oracle,在Mysql上试的结果:
使用union进行横向合并
select A_Type,A_Count
from
(select 委托
as A_Type,count() as A_Count from ....) union
(select 榜单
as A_Type,count() as A_Count from ....) union
(select 实绩
as A_Type,count(*) as A_Count from ....)