gpt4 book ai didi

mysql - SQL order by variable in inner statement

转载 作者:行者123 更新时间:2023-11-29 02:33:48 27 4
gpt4 key购买 nike

我有一个像这样的 MySQL 查询:

SELECT * 
FROM backstage
WHERE backstage_id IN (
SELECT backstage_id
FROM visitor_counter
WHERE backstage_id !=0
GROUP BY backstage_id
ORDER BY COUNT( DISTINCT ( ip_address ) ) DESC
)
LIMIT 0 , 100

我得到了我想要的结果,但我想像内部问题一样按 COUNT( DISTINCT ( ip_address ) ) DESC 排序。

关于如何执行此操作的任何提示?

最佳答案

试一试,看看它是否能满足您的需求:

select bs.*
from backstage bs
inner join
(
select backstage_id,count(distinct ip_address) as distIpCount
from visitor_counter
where backstage_id !=0
group by backstage_id
) vc on vc.backstage_id = bs.backstage_id
order by vc.distIpCount desc
limit 0,100;

关于mysql - SQL order by variable in inner statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8487177/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com