这是一个常规的SQL语句:
SELECT SUM(CASE WHEN [Column2] = 'Cylinder' THEN 1 ELSE 0 END) as 'Cylinder count',
SUM(CASE WHEN [Column2] = 'Snap' THEN 1 ELSE 0 END) as 'Snap count',
SUM(CASE WHEN [Column2] = 'Tip' THEN 1 ELSE 0 END) as 'Tip count',
SUM(CASE WHEN [Column2] = 'Other' THEN 1 ELSE 0 END) as 'Other count'
FROM [TableName]
WHERE [Column1] = '1.9 QNS-Quantity Not Sufficient'
你可以把它转换成ms-access ??
基于这个问题:
https://stackoverflow.com/questions/3153829/question-on-complex-select-statement
答案 0 :(得分:4)
Microsoft Access不支持CASE,但您可以改为使用IIF:
SELECT
SUM(IIF([Column2] = 'Cylinder', 1, 0)) as 'Cylinder count',
SUM(IIF([Column2] = 'Snap', 1, 0)) as 'Snap count',
SUM(IIF([Column2] = 'Tip', 1, 0)) as 'Tip count',
SUM(IIF([Column2] = 'Other', 1, 0)) as 'Other count'
FROM [TableName]
WHERE [Column1] = '1.9 QNS-Quantity Not Sufficient'
<强>参考强>