将 SQL 转换为 ACCESS
Posted
技术标签:
【中文标题】将 SQL 转换为 ACCESS【英文标题】:converting SQL to ACCESS 【发布时间】:2010-06-30 22:37:47 【问题描述】:这是一个常规的 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://***.com/questions/3153829/question-on-complex-select-statement
【问题讨论】:
【参考方案1】: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'
参考文献
http://office.microsoft.com/en-us/access-help/iif-function-HA001228853.aspx Case expressions in Access【讨论】:
我认为您不需要在字段别名周围加上引号。以上是关于将 SQL 转换为 ACCESS的主要内容,如果未能解决你的问题,请参考以下文章