【发布时间】:2014-12-05 21:13:42
【问题描述】:
如何在 case when 语句之间执行 sql 语句?
我正在尝试执行以下查询并收到错误:
select *,
case when 'trans_type' <> 'Stock' then
lname else (select item_name from trans_i where id = a.id limit 0,1) end as lname
from 'transaction' as a
数据库是MySql
错误:
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select item_name from trans_i limit 0,1
ps:我使用事务作为表名仅用于演示目的,它在我的真实数据库中不是“事务”。
【问题讨论】:
-
你遇到了什么错误?
-
transaction是保留字。尝试用反引号括起来:...FROM `transaction`. -
@RocketHazmat :我仅将交易用于演示目的。它不是我的真实表名。