我使用相同的选择查询两次。如何将其更改为一个查询或别名?
我的代码:
select *
from
(
select store, count(*) as quantity
from bbb
where MONTH(date) = 12
group by store
) as december
having quantity = (select MAX(maxi)
from
(
select store, count(*) as maxi
from bbb
where MONTH(date) = 12
group by store) as december
)
答案 0 :(得分:0)
如果您想选择一个追加顶级的商店,请使用:
SELECT store, COUNT(*) AS quantity
FROM bbb
WHERE MONTH(datE) = 12
GROUP BY
store
ORDER BY
quantity DESC
LIMIT 1
与原始查询不同,这个查询不会返回可能的关系。