1
整個查詢:ELT()與子查詢,而不是PARAMS
SELECT NULL,
ELT(MOD(A.contact_id, (SELECT count(*) FROM `ak_contact` WHERE `contact_type_id` = 12))+1, (SELECT CONCAT("'",GROUP_CONCAT(CAST(contact_id AS CHAR(7)) SEPARATOR "','"),"'" ) FROM `ak_contact` WHERE `contact_type_id` = 12)) as operator_id,
B.account_id, A.contact_id, A.email
FROM ak_contact A
JOIN ak_accounts B USING (contact_id)
GROUP BY A.email, A.contact_id, B.account_id
ORDER BY A.contact_id DESC
子查詢應該選擇ID中的一個號碼10493,10495,11262,11800,12362,13405,逐一對每行:
ELT(MOD(A.contact_id, (SELECT count(*) FROM `ak_contact` WHERE `contact_type_id` = 12))+1, (SELECT CONCAT("'",GROUP_CONCAT(CAST(contact_id AS CHAR(7)) SEPARATOR "','"),"'" )
#result: ELT(MOD(3333, 5)+1, '10493','10495','11262','11800','12362','13405')
問題是,我不能強制ELT(A.contact_id,子查詢)與子查詢。 要不我怎麼能做出這樣的事情:
ELT(MOD(3333, 5)+1, '10493','10495','11262','11800','12362','13405')
主查詢
謝謝,但反之亦然我需要指數得到一些ID,這樣 ELT(3,「123」,' 234','345')= 345 –
爲什麼你需要ELT?取而代之的是提供_all_值的子查詢只是在後面的位置選擇其中一個值,只需使用ORDER BY和LIMIT直接選擇您想要的值即可。 – CBroe