[英]Querying on the result of another query
我希望再次查詢括號中的查詢結果。 我在堆棧中引用了幾篇文章,並提出了以下查詢。 但是不知何故,第二個查詢(括號外的那個)不起作用。 錯誤表明第二個“組”附近語法不正確。 有人可以幫忙嗎?
select CourseID, count(CourseID)
from
(select CustomisationID, CourseID , Count(CourseID)
from tblFilter
where CustomisationID in (43, 51)
group by CourseID, CustomisationID)
group by CourseID
嘗試這個
select M.CourseID, count(M.CourseID) from
(
select CustomisationID, CourseID , Count(CourseID) AS Cnt from tblFilter where CustomisationID in (43,51)
group by CourseID, CustomisationID
)M
group by M.CourseID
您必須為子查詢設置別名。 嘗試這樣的事情:
select CourseID, count(CourseID)
from
(
select CustomisationID, CourseID , Count(CourseID) AS Cnt
from tblFilter
where CustomisationID in (43,51)
group by CourseID, CustomisationID
) AS TMP
group by CourseID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.