表如下:
| logonid | accountid |Account_Category | Account_Type |Balance |status|
| 45163023| 51004630258126|Transaction Accounts| Youth Saver|500|submit |
| 45163023| 51004630258127|Transaction Accounts| Youth Saver|500|submit |
| 45163023| 51004630258128|Transaction Accounts| Youth Saver|500| approve |
| 45163023| 51004630258129|Transaction Accounts| Youth Saver|500| submit |
| 45163023| 51004630258130|Transaction Accounts| Youth Saver|500| reject|
现在想得到
logonid 数量(=submit) balance(submit/all)
45163023 3 1500/2500
这个SQL该怎么写,谢谢
------解决方案--------------------
Select
logonid,
SUM(Case status When 'submit ' Then 1 Else 0 End) As 数量,
SUM(Case status When 'submit ' Then Balance Else 0 End) * 1.0 / SUM(Balance) As balance
From
表
Group By
logonid