【发布时间】:2015-07-14 00:35:31
【问题描述】:
我写了两个查询来连接不同条件的值,两个查询的结果应该是一样的,但是我用query2不能得到正确的结果。两个查询如下:
查询1:
SELECT group_concat(concat(concat(concat(concat(concat(f.NAME, ';') , sgk.NAME),' ') ,cc.operator),' ')) as res_string
FROM complex_check_anag cc,lnksinglechecktocomplexcheck lk,single_check_anag sgk,functionalci f ,lnkconfigurationitemtosinglecheck lkcg
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
使用 query1 我可以得到以下结果:
res_string
----------------------------------------------------------------------------------------------------------
MIL04DNS01;memory check and ,MIL04DNS01;cpu_check and
MIL04APPBOXIP01;cpu_check and ,MIL04APPBOXIP01;memory check and
Sito_Saturn_Secure;log in check and
查询2:
SELECT group_concat(concat(concat(concat(concat(concat(f.NAME, ';') , sgk.NAME),' ') ,cc.operator),' ')) as 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' and cc.complex_check_id <> cmt.comp_o_id GROUP BY sgk.NAME
使用 query2 我可以得到以下结果:
res_string
-------------------------------------------------------------------------------------------------------------------------------
MIL04DNS01;memory check and ,MIL04DNS01;cpu_check and ,MIL04DNS01;memory check and ,MIL04DNS01;cpu_check and ,MIL04DNS01;memory check and ,MIL04DNS01;cpu_check and
MIL04APPBOXIP01;cpu_check and ,MIL04APPBOXIP01;memory check and ,MIL04APPBOXIP01;cpu_check and ,MIL04APPBOXIP01;memory check and ,MIL04APPBOXIP01;cpu_check and ,MIL04APPBOXIP01;memory check and
Sito_Saturn_Secure;log in check and ,Sito_Saturn_Secure;log in check and ,Sito_Saturn_Secure;log in check and and ,MIL04DNS01;memory check and ,MIL04APPBOXIP01;memory check and
你能给我一些修改 query2 以获得与 query1 相同的结果吗?...非常感谢。
【问题讨论】:
-
仅供参考,我什至不考虑查看查询,只要它们的格式是这样的。实际上它们根本没有格式化。当您使用它时,您可以熟悉 1992 年成为标准的连接语法并立即使用它。这只是一个难以理解的混乱。
-
能否提供 sqlfiddle 数据样本??
标签: mysql select group-by group-concat