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

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

Keep getting syntax error message in Toad Data Point

问题

I have a table like this:

  1. 员工编号 性别
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5

我只想把它透视成这样:

  1. 员工编号 3 2

我写的查询非常简单:

  1. SELECT sum(CASE 性别 WHEN '男' THEN 1 ELSE 0 END) 男,
  2. sum(CASE 性别 WHEN '女' THEN 1 ELSE 0 END)
  3. FROM 表格

但我总是收到这个消息:

  1. [Microsoft][ODBC Excel Driver] 查询表达式中缺少运算符的语法错误 ''sum(CASE 性别 WHEN '男' THEN 1 ELSE 0 END) 男''

有人知道如何修复它吗?

英文:

I have a table like this:

  1. Employee ID Gender
  2. 1 F
  3. 2 F
  4. 3 M
  5. 4 M
  6. 5 M

I just want to pivot it like this:

  1. M F
  2. Employee 3 2

The query I wrote is very simple:

  1. SELECT sum(CASE Gender WHEN 'M' THEN 1 ELSE 0 END) M,
  2. sum(CASE Gender WHEN 'F' THEN 1 ELSE 0 END) F
  3. FROM Table

And I always get this message:

  1. [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()

  1. SELECT SUM(IIF(Gender = 'M', 1, 0)) AS 男性,
  2. SUM(IIF(Gender = 'F', 1, 0)) AS 女性
  3. FROM 表名;
英文:

CASE is not supported by the ODBC Excel Driver.<br/>

Instead use the function IIF():

  1. SELECT SUM(IIF(Gender = &#39;M&#39;, 1, 0)) AS M,
  2. SUM(IIF(Gender = &#39;F&#39;, 1, 0)) AS F
  3. 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:

确定