我有一个sql给我这个数据:
Dim MySqlString As String = "SELECT USERID, "
MySqlString += "SUM(case when ACTVCODE = 'POC' then 1 else 0 end) POC, "
MySqlString += "SUM(case when ACTVCODE = 'PIC' then 1 else 0 end) PIC, "
MySqlString += "SUM(case when ACTVCODE = 'EML' then 1 else 0 end) EML, "
MySqlString += "SUM(case when ACTVCODE = 'AD' then 1 else 0 end) AD, "
MySqlString += "SUM(case when RESULTCODE = 'LOG' then 1 else 0 end) LOG, "
MySqlString += "SUM(case when RESULTCODE = 'SR' then 1 else 0 end) SR, "
MySqlString += "SUM(case when RESULTCODE = 'DM' then 1 else 0 end) DM, "
MySqlString += "SUM(case when RESULTCODE = 'GK' then 1 else 0 end) GK, "
MySqlString += "SUM(case when RESULTCODE = 'AM' then 1 else 0 end) AM, "
MySqlString += "SUM(case when RESULTCODE = 'NA' then 1 else 0 end) NA, "
MySqlString += "SUM(case when RESULTCODE = 'RO' then 1 else 0 end) RO, "
MySqlString += "SUM(case when RESULTCODE = 'ORE' then 1 else 0 end) ORE, "
MySqlString += "SUM(case when RESULTCODE = 'COM' then 1 else 0 end) COM, "
MySqlString += "SUM(case when RESULTCODE = 'SMS' then 1 else 0 end) SMS, "
MySqlString += "SUM(case when RESULTCODE = 'SV' then 1 else 0 end) SV, "
MySqlString += "SUM(case when RESULTCODE = 'QUO' then 1 else 0 end) QUO, "
MySqlString += "SUM(case when RESULTCODE = 'PQU' then 1 else 0 end) PQU "
我正在尝试在最后添加一列来汇总每一行。我尝试使用SUM(POC + PIC + EML + AD + LOG),但这不像我想象的那样工作。有什么建议吗?
答案 0 :(得分:6)
您不需要SUM:
POC + PIC + EML + AD + LOG