gpt4 book ai didi

MySQL:使用 SUM 查询(如果 ..)

转载 作者:行者123 更新时间:2023-11-29 12:04:21 26 4
gpt4 key购买 nike

请帮我查询:

SELECT 
N.site_name,
Count(N.site_name),
SUM (IF((SC.type_conn = 'GET') && (SC.type_conn = 'CONNECT'),N.size_site,0)) as Traffic_IN,
SUM (IF(SC.type_conn = 'POST',N.size_site,0)) as Traffic_OUT
From
news N,
status_conn SC,
users U
where
N.id_conn = SC.id_conn and
N.id_user = U.id_user and
U.name_user = 'max' and
N.date_conn = '2015-08-04'
Group by
N.site_name
Order by
SUM (IF((SC.type_conn = 'GET') && (SC.type_conn = 'CONNECT'),N.size_site,0))

最佳答案

我不知道女巫是问题所在;无论如何你可以尝试这个:

Select N.site_name, 
Count(N.site_name),
SUM (IF((SC.type_conn = 'GET') && (SC.type_conn = 'CONNECT'),N.size_site,0)) as Traffic_IN,
SUM (IF(SC.type_conn = 'POST',N.size_site,0)) as Traffic_OUT
From news N, status_conn SC, users U
where N.id_conn = SC.id_conn
and N.id_user = U.id_user
and U.name_user = 'max'
and N.date_conn = '2015-08-04'
Group by N.site_name
Order by Traffic_IN

否则

select ...
...
Order by 3

关于MySQL:使用 SUM 查询(如果 ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31802831/

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