gpt4 book ai didi

mysql case 语句无法正常工作

转载 作者:行者123 更新时间:2023-11-29 10:36:22 25 4
gpt4 key购买 nike

我知道这不是一个应该在这里问的问题。请帮助我找到解决方案。

我尝试在下面的查询中使用 case 语句,但我找不到我在其中所做的错误。请帮助我..

SELECT
tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord
(CASE WHEN tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord == 'NVA' THEN 'NON_ValueAccessory'),
COUNT(tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord) Ccord_count
FROM
tsc_accessory_details_for_repaired_and_qc_pass_phone_list
WHERE
tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord = 'NVA'
GROUP BY
tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord

收到如下错误

SQL]SELECT tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord (CASE WHEN tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord == 'NVA' THEN 'ok'), COUNT(tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord) Ccord_count FROM tsc_accessory_details_for_repaired_and_qc_pass_phone_list WHERE tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord = 'NVA' GROUP BY tsc_accessory_details_for_repaired_and_qc_pass_phone_list.Ccord

[Err] 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 '== 'NVA' THEN 'ok'), COUNT(tsc_accessory_details_for_repaired_and_qc_pass_phon' at line 3

最佳答案

你的表名太长了。您必须使用较短的名称,或者如果无法缩短,则仅使用同义词。尝试这个查询 -

SELECT ta.Ccord
, (CASE WHEN ta.Ccord = 'NVA' THEN 'NON_ValueAccessory' END)
, COUNT(ta.Ccord) Ccord_count
FROM tsc_accessory_details_for_repaired_and_qc_pass_phone_list ta
WHERE ta.Ccord = 'NVA'
GROUP BY ta.Ccord, ta.Ccord

关于mysql case 语句无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com