英文:
Keep getting syntax error message in Toad Data Point
问题
I have a table like this:
员工编号 性别
1 女
2 女
3 男
4 男
5 男
我只想把它透视成这样:
男 女
员工编号 3 2
我写的查询非常简单:
SELECT sum(CASE 性别 WHEN '男' THEN 1 ELSE 0 END) 男,
sum(CASE 性别 WHEN '女' THEN 1 ELSE 0 END) 女
FROM 表格
但我总是收到这个消息:
[Microsoft][ODBC Excel Driver] 查询表达式中缺少运算符的语法错误 ''sum(CASE 性别 WHEN '男' THEN 1 ELSE 0 END) 男''。
有人知道如何修复它吗?
英文:
I have a table like this:
Employee ID Gender
1 F
2 F
3 M
4 M
5 M
I just want to pivot it like this:
M F
Employee 3 2
The query I wrote is very simple:
SELECT sum(CASE Gender WHEN 'M' THEN 1 ELSE 0 END) M,
sum(CASE Gender WHEN 'F' THEN 1 ELSE 0 END) F
FROM Table
And I always get this message:
[Microsoft][ODBC Excel Driver] Syntax error (missing operator) in query expression 'sum(CASE Gender WHEN 'M' THEN 1 ELSE 0 END) M'.
Anyone knows how to fix it?
答案1
得分: 0
CASE
不受ODBC Excel驱动程序支持。<br/>
请改用函数IIF()
:
SELECT SUM(IIF(Gender = 'M', 1, 0)) AS 男性,
SUM(IIF(Gender = 'F', 1, 0)) AS 女性
FROM 表名;
英文:
CASE
is not supported by the ODBC Excel Driver.<br/>
Instead use the function IIF()
:
SELECT SUM(IIF(Gender = 'M', 1, 0)) AS M,
SUM(IIF(Gender = 'F', 1, 0)) AS F
FROM tablename;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论