在Toad Data Point中一直收到语法错误消息。

huangapple go评论58阅读模式
英文:

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 = &#39;M&#39;, 1, 0)) AS M, 
       SUM(IIF(Gender = &#39;F&#39;, 1, 0)) AS F 
FROM tablename;

huangapple
  • 本文由 发表于 2023年4月19日 22:44:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定