我很好奇是否有人可以帮助我。
这是表格和字段: enter image description here
这是我得到的例子:
这就是我到目前为止
Select ipno,
SUM(IF(retcode<100,0)) As '<100',
SUM(IF(retcode>=100 and retcode<200,0)) As '100s',
SUM(IF(retcode>=200 and retcode<300,0)) As '200s',
SUM(IF(retcode>=300 and retcode<400,0)) As '300s',
SUM(IF(retcode>=400,0)) As '400s'
From WebLog
Group By ipno;
但我一直收到此错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) As '<100',
SUM(IF(retcode>=100 and retcode<200,0)) As '100s',
SUM(IF(retcod' at line 2
答案 0 :(得分:0)
你不需要MySQL中的if()
:
Select ipno,
SUM(retcode < 100) As `<100`,
SUM(retcode >= 100 and retcode < 200) As `100s`,
SUM(retcode >= 200 and retcode < 300) As `200s`,
SUM(retcode >= 300 and retcode < 400) As `300s`,
SUM(retcode >= 400) As `400s`
From WebLog
Group By ipno;
MySQL将布尔表达式视为数字上下文中的数字,使用&#34; 1&#34;对于真实的d&#34; 0&#34;为假。
此外,不要使用单引号作为列别名。仅对日期和字符串常量使用单引号。
答案 1 :(得分:0)
这对我也有用。谢谢大家。
#1e1d22