【问题标题】:mysqli case issue select from inside casemysqli 案例问题 从内部案例中选择
【发布时间】:2015-10-02 09:34:08
【问题描述】:

你好,这是我的代码,任何人都可以建议我哪里出错了,因为我遇到了错误

select m.verify 
CASE eore WHEN '1' THEN c.mobile from epmem m, empl c 
WHEN '2' THEN c.gender from epmem m, comp c 
ELSE NULL END, 
as 'expose' where (c.rid=m.mid) order by mid desc limit 50

错误是

 #1064 - Erreur de syntaxe près de 
'CASE eore WHEN '1' THEN c.mobile 
 from epmem m, empl c WHEN '2' THEN c.gender fro' Ã  la ligne 1 

这就是我想要达到的目标 我想将一张桌子与另一张桌子连接起来,另一张桌子是动态的,将根据案例价值....

我想要的是在案例 1 中将 empl 与 epmem 连接,在案例 2 时将 comp 与 epmem 连接,并在代码中选择相关数据......

【问题讨论】:

  • 逗号在m.verifyEND 之后c.mobile 之后
  • 您应该 (a) 发布您遇到的错误并 (b) 格式化您的代码,使其更具可读性。一旦代码格式正确,您可能会惊讶地发现错误。
  • 更新了问题

标签: php mysql case


【解决方案1】:

每个CASE 语句都有END

SELECT m.verify,m.mid,
CASE eore
WHEN '1' THEN c.mobile
WHEN '2' THEN d.gender
ELSE NULL END AS 'expose'
FROM epmem m 
INNER JOIN empl c ON c.rid = m.mid
INNER JOIN comp d ON d.rid = m.mid
ORDER BY m.mid DESC
LIMIT 50

编辑:

SELECT m.mid,m.email,m.eore,m.date,m.ipj,m.verify,
    CASE eore WHEN '1' THEN d.mobile else c.gender END as expose1,
    CASE eore WHEN '1' THEN d.profile else c.profile END as expose2,
    CASE eore WHEN '1' THEN d.veri else c.mobile END as expose3
FROM epmem m
JOIN empl c ON c.rid = m.mid
JOIN comp d ON d.rid = m.mid
ORDER BY m.mid DESC
LIMIT 50

【讨论】:

  • 加入总是不与 empl 它取决于案例值请查看有问题的代码 case 1 hoin with empl 和 case 2 join with comp
  • 好吧,您的问题中只有一个案例。 @sonamSharma
  • 我有两个case,每个case里面都有一个from语句
  • @sonamSharma if empl.rid = epmem.mid so epmem.mid = 表 comp 中的哪一列?因为我们需要连接这 3 个表。
  • 代码有效,但是当我添加另一个字段时,例如 WHEN '1' THEN c.mobile,c.profile 然后它显示错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-12
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多