을 감상 할 수있다 당신이 실제로 필요한 것은 같은 :
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
: 당신이 이것을 실행하려고하면
SELECT
cat.cat_id, cat.cat_name, item_id, item_author, item_name, item_pic_big
FROM item_table a
JOIN cat_table b ON a.cat_id = b.cat_id
WHERE a.item_id IN (SELECT item_id
FROM item_table
WHERE cat_id = b.cat_id
LIMIT 5)
GROUP BY a.item_id
ORDER BY b.cat_id
불행하게도, 당신이 실망 오류 메시지가 표시됩니다
해결 방법이 필요합니다. 현재 가능한 해결 방법의 목록을 볼 수 있습니다 : http://www.artfulsoftware.com/infotree/queries.php#104
편집 :가 첫 번째 솔루션은 다음과 같이 당신의 구조로 변환 할 수 있습니다 (나는 테이블을 가지고 있지 않기 때문에 약간의 열 이름이있을 수 있습니다 문제)
SELECT temp2.cat_id, temp2.item_id,
temp2.cat_name, temp2.item_author,
temp2.item_name, temp2.item_pic_big
FROM
(SELECT
temp.cat_id,
temp.item_id,
temp.cat_name,
temp.item_author,
temp.item_name,
temp.item_pic_big,
IF(@prev <> temp.cat_id, @rownum := 1, @rownum := @rownum+1) AS rank,
@prev := temp.cat_id
FROM (SELECT
a.item_id,
b.cat_id,
b.cat_name,
a.item_author,
a.item_name,
a.item_pic_big
FROM item_table a
JOIN cat_table b ON a.cat_id = b.cat_id
ORDER BY cat_id, item_id) AS temp
JOIN (SELECT @rownum := NULL, @prev := 0) AS r
ORDER BY temp.cat_id, temp.item_id) as temp2
WHERE temp2.rank <= 5
ORDER BY temp2.cat_id, temp2.item_id;
복잡한 ... ... 감사합니다 –
@Itai - Ein Be'aya :) – Galz