2013-03-01 71 views
-4

任何人都可以更正此查詢嗎?我的Sql查詢錯誤

SELECT m.id, GROUP_CONCAT(IF((SUBSTR(r.role_name , -1) = 's') , (SUBSTR(r.role_name, 1, (LENGTH(r.role_name) -1)) , (r.role_name)) SEPARATOR ',') AS role_name 
FROM member m 
    JOIN `member_roles` mr ON mr.`member_id` = m.`id` 
    JOIN roles r ON r.id = mr.role_id 
WHERE m.id IN (1825, 1822, 1738, 1737, 1736, 1735, 1734, 1733, 1732, 1730, 1729, 1728, 1725, 1723, 1722, 1721, 1719, 1717, 1716, 1715, 1714, 1712, 1711, 1710, 1709) 
GROUP BY m.id 
+0

是的,有人可以:P好了,現在認真了,有什麼問題?你有錯誤嗎?還是它沒有做你想做的事?而且,你想要它做什麼? – aaaaaa123456789 2013-03-01 10:57:16

+0

你能解釋一下你得到的錯誤還是錯誤的輸出? – araknoid 2013-03-01 10:57:55

+0

得到任何錯誤?如果是顯示錯誤類型 – 2013-03-01 10:58:22

回答

0

語法錯誤,在GROUP_CONCAT函數中。試試這個查詢 -

SELECT 
    m.ID, 
    GROUP_CONCAT(IF(SUBSTR(r.role_name, - 1) = 's', SUBSTR(r.role_name, 1, LENGTH(r.role_name) - 1), r.role_name) SEPARATOR ',') AS role_name 
FROM member m 
    JOIN member_roles mr 
    ON mr.member_id = m.ID 
    JOIN roles r 
    ON r.ID = mr.role_id 
WHERE m.ID IN (1825, 1822, 1738, 1737, 1736, 1735, 1734, 1733, 1732, 1730, 1729, 1728, 1725, 1723, 1722, 1721, 1719, 1717, 1716, 1715, 1714, 1712, 1711, 1710, 1709) 
GROUP BY m.ID 
+0

非常感謝你:) – Anu 2013-03-01 11:02:06