0

我两次使用相同的选择查询。如何将其更改为一个查询或别名?

我的代码:

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 
                )
4

1 回答 1

0

如果您想选择一个排名靠前的商店,请使用以下命令:

SELECT  store, COUNT(*) AS quantity
FROM    bbb
WHERE   MONTH(datE) = 12
GROUP BY
        store
ORDER BY
        quantity DESC
LIMIT   1

与您的原始查询不同,此查询不会返回可能的关系。

于 2013-01-17T18:03:33.177 回答