2011-09-28 88 views
0
SELECT htpid AS parentid 
    FROM likehot WHERE htpid 
    IN (SELECT id FROM bultin WHERE DATE >= '1317108749') 
    GROUP BY htpid ORDER BY COUNT(htpid) 
    DESC 

給出結果如何結合這兩個查詢?

parentid 
16060 
16059 
16058 
16057 

等查詢

SELECT app_id,bultin.id,photo_album_id,entcmmnt_id,link_url,youtubeLink, 
     link_image,id, mem_id, subj, body, bultin.date,parentid, 
     from_id, visible_to, image_link,post_via 
FROM bultin 
WHERE id IN ('16062','16059','16058','16057') 
ORDER BY FIELD('16062','16059','16058','16057') 
LIMIT 5 

其實我想同序列的是,在IN所以我用現場操作員

請推薦 感謝

+0

@ MarkByers,我想讓他們在單個查詢中運行.. – Sparkx

+0

勇敢的男人在一個單一的查詢運行 –

+0

@臨牀不過,你們有沒有答案.. – Sparkx

回答

0

我無法理解nd你的問題..如果你可以請解釋一個更好的方法..我可以給你解決方案..我想說,你不能使用多一個值在第一個查詢「SELECT id FROM bultin WHERE DATE> ='1317108749')「。還有一件事y不u使用在第一個五年這樣的查詢

值選擇htpid AS的parentid FROM likehot WHERE htpid IN(16062' , '16059', '16058', '16057')

+0

通過'htpid IN(16062','16059 ','16058','16057')'是第一個列表中的結果。 – Sparkx

0

如果我沒有錯過任何東西,這應該做的工作:

SELECT b.app_id, b.id, b.photo_album_id, b.entcmmnt_id, b.link_url, b.youtubeLink, 
    b.link_image, b.mem_id, b.subj, b.body, b.date, b.parentid, 
    b.from_id, b.visible_to, b.image_link, b.post_via 
FROM bultin AS b 
JOIN (
    SELECT htpid, COUNT(htpid) AS htpid_count 
    FROM likehot 
    GROUP BY htpid ORDER BY COUNT(htpid) 
    DESC 
) AS l ON l.htpid = b.id 
WHERE DATE >= '1317108749' 
ORDER BY l.htpid_count 
LIMIT 5 

讓我知道如果您需要了解此查詢更多詳情。

+0

我想你應該從子查詢中刪除'ORDER BY COUNT(htpid)'。 –

+0

原來是'GROUP BY htpid ORDER BY COUNT(htpid)',這就是爲什麼我認爲優化版本應該像這樣在子查詢中排序,並且還要在主查詢中由l.htpid_count排序 – cephuo