主题:sql中union多个(2个以上)表的联合查询
create table zw.tab1 as
select distinct callerno from icd.tbilllog5 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog6 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog7 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog8 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog9 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog10 where partid<11 having by substr(callerno,1,1)=1;
其中icd.tbilllogX表示每个月的数据表,icd.tbilllog10 where partid<11 表示10月1日到10日的数据,
substr(callerno,1,1)=1表示要查询的callerno的第一个是1;但是运行说有错误。
求解释解决谢谢!
select distinct callerno from icd.tbilllog5 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog6 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog7 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog8 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog9 where substr(callerno,1,1)=1
union
select distinct callerno from icd.tbilllog10 where partid<11 having by substr(callerno,1,1)=1;
其中icd.tbilllogX表示每个月的数据表,icd.tbilllog10 where partid<11 表示10月1日到10日的数据,
substr(callerno,1,1)=1表示要查询的callerno的第一个是1;但是运行说有错误。
求解释解决谢谢!