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,这种写法不熟,多谢。
相关阅读
Cheat sheet for Zenny's interview questions请教sql server temptable # 和 ##sql server 面试题 (1)MySQL founder quits Sun(ZZ)请推荐一本自学SQL的书吧which one is the default?sql面试题2新人报道how to check the definition of a stored procedure in TOAD我找工作,如果有空缺请说一下。请教比较两个table,找出相同和不同的recordsRookie's question: How to combine two tables horizontallyexcel problem请教一个新手的shift column问题今天惊闻......sql server 面试题 (6) sql server 面试题 (5)Oracle and HP(ZZ)how to store a trie into database?菜鸟来问个菜鸟级别问题