跪求一SQL储存过程(没分了...请帮帮忙啊!)
把多个表tabl1,tabl2,tabl3,tabl4,tabl,table6中的int类型的Num,Cout列根据定义的变量@ID合并查询出来.效果如下:
Num Cout
123 120
1203 20
........
------解决方案--------------------select Num,Cout from table1 union all
select Num,Cout from table2 union all
....
------解决方案----------------------合併重復
Select Num, Cout From tabl1
Union
Select Num, Cout From tabl2
Union
Select Num, Cout From tabl3
Union
Select Num, Cout From tabl4
Union
Select Num, Cout From tabl5
Union
Select Num, Cout From tabl6
--不合併重復
Select Num, Cout From tabl1
Union All
Select Num, Cout From tabl2
Union All
Select Num, Cout From tabl3
Union All
Select Num, Cout From tabl4
Union All
Select Num, Cout From tabl5
Union All
Select Num, Cout From tabl6
------解决方案--------------------leaf110() ( ) 信誉:100 2007-7-18 18:14:56 得分: 0
能否计算出合并后的总数....
--------------------------
這個意思?
Select Num, SUM(Cout) As Cout
From
(
Select Num, Cout From tabl1
Union All
Select Num, Cout From tabl2
Union All
Select Num, Cout From tabl3
Union All
Select Num, Cout From tabl4
Union All
Select Num, Cout From tabl5
Union All
Select Num, Cout From tabl6
) A
Group By
Num