group by 2表 统计问题(5分)

  • 主题发起人 主题发起人 maill01
  • 开始时间 开始时间
M

maill01

Unregistered / Unconfirmed
GUEST, unregistred user!
A表 <br>ID DATA1 &nbsp; &nbsp; &nbsp; &nbsp; SL1<br>1 &nbsp;2008-01-01 &nbsp; &nbsp;10<br>2 &nbsp;2008-01-01 &nbsp; &nbsp;12<br>3 &nbsp;2008-01-06 &nbsp; &nbsp;20<br>4 &nbsp;2008-01-09 &nbsp; &nbsp;23<br><br>B表<br>ID DATA2 &nbsp; &nbsp; &nbsp; SL2<br>1 &nbsp;2008-01-01 &nbsp; 5<br>2 &nbsp;2008-01-05 &nbsp; 8<br>3 &nbsp;2008-01-05 &nbsp; 15<br><br>如何实现如下的统计结果:<br><br>DATA1 &nbsp; &nbsp; &nbsp; &nbsp; SL11(SL1的合计) &nbsp;DATA2 &nbsp; &nbsp; &nbsp; &nbsp;SL22(SL2的合计)<br>2008-01-01 &nbsp; &nbsp;10+12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2008-01-01 &nbsp; 5<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2008-01-05 &nbsp; 8+15<br>2008-01-06 &nbsp; &nbsp;20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>2008-01-09 &nbsp; &nbsp;23
 
select data1, sum(sl1) as sl11, data2, sum(sl2) as sl22 from a full join b on a.data1=b.data2 group by data1, data2<br>没测试随手写的.
 
他要的结果好像是data1和data2是两列吧。<br>select date1,sum(sl1),data2,sum(sl2) from a join b on a.data1=b.data2 group by convert(char(10),date)1+convert(char(10),data2)
 

Similar threads

D
回复
0
查看
778
DelphiTeacher的专栏
D
D
回复
0
查看
818
DelphiTeacher的专栏
D
A
回复
0
查看
819
Andreas Hausladen
A
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部