p*t
2 楼
Given the following table, TRADE:
TRADE
Account BuySell Quantity
------- ------- --------
XXX B 500
XXX S 100
YYY S 1100
ZZZ S 300
Outline the SQL required to produce the following output:
Account Position
------- --------
XXX 400
YYY -1100
ZZZ -300
谢谢了。
TRADE
Account BuySell Quantity
------- ------- --------
XXX B 500
XXX S 100
YYY S 1100
ZZZ S 300
Outline the SQL required to produce the following output:
Account Position
------- --------
XXX 400
YYY -1100
ZZZ -300
谢谢了。
B*g
4 楼
SELECT t.account,SUM(CASE t.buysell WHEN 'B' THEN t.quantity ELSE t.quantity
*-1 END) Position
FROM trade t
GROUP BY t.account
【在 p*****t 的大作中提到】
: Given the following table, TRADE:
: TRADE
: Account BuySell Quantity
: ------- ------- --------
: XXX B 500
: XXX S 100
: YYY S 1100
: ZZZ S 300
: Outline the SQL required to produce the following output:
: Account Position
*-1 END) Position
FROM trade t
GROUP BY t.account
【在 p*****t 的大作中提到】
: Given the following table, TRADE:
: TRADE
: Account BuySell Quantity
: ------- ------- --------
: XXX B 500
: XXX S 100
: YYY S 1100
: ZZZ S 300
: Outline the SQL required to produce the following output:
: Account Position
a*o
7 楼
受益匪浅,以前只在PL/SQL里用过一点CASE,这种写法不熟,多谢。
相关阅读
who's using object oriented database?请教oracle8如何用database securityODBCFree Database List[转载] Why I am applying for Database BM嘻嘻,上任了何谓面向对象的数据库你们喜欢用哪个SQL Tools?数据库入门知识之3(关系数据库)SQL server 和SQL anywhere的区别是什么?I want to learn something from here... 数据库入门知识之4(数据库应用程序)从Technet那里拿的Oracle光盘版本有什么限制?What is default USERNAME and PASSWORD数据库知识入门之2.(数据库管理系统简介)祝贺搬猪database and MUDQuestions on SQLSybase中如何设置定时执行的存储过程