我有如下2010 MS-訪問SQL查詢:申請和
SELECT
EXC AS MY_EXC,
COUNT(FC_CUSIP) AS MY_FC_CUSIP
FROM
TESTDATA t
WHERE
FC_CUSIP <> "NULL"
GROUP BY
EXC
UNION ALL
SELECT
EXC AS MY_EXC,
0 AS MY_FC_CUSIP
FROM
TESTDATA t
WHERE
FC_CUSIP = "NULL"
GROUP BY
EXC
ORDER BY
MY_EXC ASC;
結果如下:
MY_EXC | MY_FC_CUSIP
--------+---------------
AA | 0
AM | 0
AM | 9
BB | 0
DD | 10
DD | 0
F | 0
I | 0
NM | 0
NM | 131
NY | 0
NY | 184
OO | 0
OO | 14
PC | 0
VA | 0
Z | 0
Z | 2
我需要進一步的SQL這可以給出結果等作爲下面: 基本上它將不同MY_EXC和總和即MY_FC_CUSIP
MY_EXC | MY_FC_CUSIP
--------+---------------
AA | 0
AM | 9
BB | 0
DD | 10
F | 0
I | 0
NM | 131
NY | 184
OO | 14
PC | 0
VA | 0
Z | 2
PLE ase以任何方式幫助我......實際上,我通過VBA動態創建了整個sql字符串。
我已經嘗試過這樣的: – pmr
它給出了查詢操作的語法錯誤(缺少操作)「a.MY_EXC SUM(a.MY_FC_CUSIP)」 – pmr
@purnendumaity現在嘗試,錯過了一個逗號 – Matt