当前位置: 代码迷 >> Sql Server >> 帮忙看下这个查询SQL如何写
  详细解决方案

帮忙看下这个查询SQL如何写

热度:66   发布时间:2016-04-27 21:04:22.0
帮忙看下这个查询SQL怎么写
表如下:
|   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
  相关解决方案