我寫了兩個查詢以不同條件連接值,兩個查詢的結果應該是一樣的,但是我無法用query2得到正確結果。兩個查詢如下:group_concat重複值
query1:
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
QUERY2:
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
你能給我一些suffestions修改QUERY2獲得與QUERY1相同的結果...感謝了很多?
僅供參考,我甚至不考慮在查詢,只要他們被格式化這樣的期待。其實他們根本沒有格式化。當你處理它時,你可以熟悉1992年制定的聯合語法,並立即使用它。這只是一個難以理解的混亂。 – fancyPants
您能否提供帶有數據樣本的sqlfiddle? – Alex