【发布时间】:2015-07-08 11:18:12
【问题描述】:
我在mysql环境中写了sql代码来连接数据。但是,我无法得到正确的结果,而且我对我的 sql 代码有什么问题感到困惑。我的sql代码如下:
SELECT case when cc.complex_check_id = cmt.comp_o_id then cc.status cstatus,sgk.status sgstatus,cc.NAME complex_check_name,cc.min min_flag,cmt.comp_t_name cmpt_name,group_concat(concat(concat(concat(concat(concat(f.NAME, ';') , sgk.NAME),' ') ,cc.operator),' '))
else cc.status cstatus,sgk.status sgstatus,cc.NAME complex_check_name,cc.min min_flag,'not' as cmpt_name,group_concat(concat(concat(concat(concat(concat(f.NAME, ';') , sgk.NAME),' ') ,cc.operator),' ')) end res_string
FROM complex_check_anag cc,lnksinglechecktocomplexcheck lk,single_check_anag sgk,functionalci f ,lnkconfigurationitemtosinglecheck lkcg,comp_t_anag cmt
WHERE cc.complex_check_id = lk.complex_check_id AND sgk.single_check_id = lk.single_check_id and f.id = lkcg.config_item_id
and sgk.single_check_id = lkcg.single_check_id and sgk.status = 'active' GROUP BY cc.NAME
您能给我一些建议吗?...非常感谢你们!
【问题讨论】:
-
I couldn't get the correct result描述性不强。 -
对不起,我的意思是执行查询时有错误信息
-
这更接近了,但还有两件事:错误消息究竟是什么,以及正确的结果是什么(您要达到什么目的)。请把这些放在问题中。
-
错误消息是:“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在 'cstatus,sgk.status sgstatus,cc.NAME 附近使用的正确语法complex_check_name,cc.min min_flag,cmt.comp_' 在第 1 行 "
-
正确的结果应该是,当"case"条件满足时:"active active AN1WVS01 0 not MIL04APPBOXIP01;cpu_check and ,MIL04APPBOXIP01;memory check and " ;当“case”条件不满足时:“active active AQ1PVS01 0 AL1WVS01 MIL04DCW003;cpu test check and”
标签: mysql case concat group-concat .when