我有以下SQL:

SELECT count(clics)
FROM clicscount
WHERE date > CURDATE() - INTERVAL 1 WEEK

结果是上周点击次数的总和。
源数据示例:
Thursday:  5 clics
Friday:    5 clics
Saturday:  5 clics
Sunday:    5 clics
Monday:    5 clics
Tuesday:   5 clics
Wednesday: 5 clics
Today:     5 clics

显示的结果是40,因为函数显示所有单击的总和。
但是,我想以每天单击的数组显示数据,例如:
5,5,5,5,5,5,5,5

最佳答案

你可以这样做:

SELECT GROUP_CONCAT(tmp.c SEPARATOR ',')
FROM (
  SELECT count(clics) c
  FROM clicscount
  WHERE date > CURDATE() - INTERVAL 1 WEEK
  GROUP BY date
) as tmp;

关于mysql - 函数计数数据结果分隔为逗号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32255256/

10-09 16:56