0
這裏就是我試圖做一個例子:與現場選擇爲選擇statment(?這是什麼所謂的)
我有按月/年舉辦活動的列表與事件的計數,然後是這些事件的ID的逗號列表。
以下是我有:
SELECT count(*) as counter,
MONTHNAME(publishDate) as month,
YEAR(publishDate) as year
FROM bursch.events
GROUP BY YEAR(publishDate),
MONTH(publishDate)
order by year desc;
,但除此之外,我需要這些ID太(2,5,6)< < <這樣的:
這裏的理念是:
SELECT count(*) as counter,
MONTHNAME(publishDate) as month,
YEAR(publishDate) as year,
(select id
from events
where 'call conditions affect the main query') as IDList
FROM events
GROUP BY YEAR(publishDate),
MONTH(publishDate)
order by year desc;
這會導致這樣的事情:
counter | month | year | ids
-----------------------------------------
3 | June | 2013 | 45,49,50
4 | July | 2013 | 39,40,41,42
2 | March | 2011 | 33,34
5 | May | 2011 | 27,29,30,31,32
1 | June | 2011 | 22
4 | July | 2011 | 14,17,18,19
1 | January | 2010 | 13
這將是偉大的我可以根據主選擇語句的條件我的選擇結果。可能有更好的方法來獲得這個結果。也許一個更簡單的方法。但選擇作爲領域的一部分。那會叫什麼?相關查詢?不確定。我已經看到,我可以在Oracle和MySQL中實現這一點,並且它派上用場(如果我只知道它叫做什麼的話)。
謝謝先進。讓我知道,如果有什麼不清楚。
有它!不錯的工作... –