table1 和 table2的表结构一致其中包含列
SLJG(里面保存字符串 1 or 2 or 3)
需要将多个这样的表的结构根据SLJG求和例如
table1:
SLJG
1
2
2
3
3
3table2:
SLJG
1
2
2
3
3
3table3:
SLJG
1
2
2
3
3
3以后可能还要更多的表
需要的查询结果是SLJG cout
1 3
2 6
3 9
谢谢大家了
SLJG(里面保存字符串 1 or 2 or 3)
需要将多个这样的表的结构根据SLJG求和例如
table1:
SLJG
1
2
2
3
3
3table2:
SLJG
1
2
2
3
3
3table3:
SLJG
1
2
2
3
3
3以后可能还要更多的表
需要的查询结果是SLJG cout
1 3
2 6
3 9
谢谢大家了
select SLJG,count(*) as cout
from
(select * from table1
union all
select * from table2
union all
select * from table3
--...) a
group by a.SLJG
修改下,表别人被注释了
select SLJG,count(*) as cout
from
(select * from table1
union all
select * from table2
union all
select * from table3
--...
) a
group by a.SLJG
from
(select * from table1
union all
select * from table2
union all
select * from table3
--...) a
group by a.SLJG