请帮写一个SQL查询,100大分,赶紧来抢啊(100分)

  • 主题发起人 主题发起人 xq
  • 开始时间 开始时间
X

xq

Unregistered / Unconfirmed
GUEST, unregistred user!
现有下一表:
SERIAL_NO DEPART NUM PRICE TYPE
1 1 3 10.10 1
2 2 10 9.00 1
3 5 3 8.90 2
4 3 5 4.30 1
5 7 10 1.90 2
... ... ... ... ...
部门(DEPART)有多个,类型(TYPE)有多种,请统计出类型为1 和2
的NUM*PRICE (类型1 SUM_IN, 类型2 SUM_OUT),查询出后列出的表为:
DEPART SUM_IN SUM_OUT
1 .... ....
2 .... ....
3 .... ...
...
 
select a.depart as depart, sum(a.num*a.price) as sum_in, sum(b.num*b.price) as sum_out
from your_table a, your_table b
where a.depart = b.depart and a.type = 1 and b.type = 2
group by depart order by depart
 
SELECT DEPART,SUM(NUM*PRICE*(2-TYPE)) AS SUM_IN,
SUM(NUM*PRICE*(TYPE-1)) AS SUM_OUT
FROM TABLE
GROUP BY DEPART
ORDER BY DEPART
 
Another_eYes:
与本人写法相同,统计结果不太正确
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
850
import
I
I
回复
0
查看
772
import
I
后退
顶部