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

时间:2015-08-04 07:09:46

标签: mysql sql

请帮我查询:

<?php
    if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod')){  
        header('Location: http://yoursite.com/iphone');
        exit();
    }
?>

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

在查询结束时,您可能会遇到括号问题。试试

[...] ORDER BY SUM (IF((SC.type_conn = 'GET') && (SC.type_conn = 'CONNECT')),N.size_site,0)