Q132284591 发表于 2018-9-28 10:09:35

MYSQL中分类汇总

  最近应用到一天充值的统计
  比如跟下表 需求汇总每天每个页面进入的成功充值额total,与充值人数num,充值人次people
  (人数跟人次的区别就像PV与UV的区别,同一个人可以充值n次,人数为1,人次为n)
  status 1 充值成功 0失败
  表类似:
  Id
  uid
  money
  page
  status
  date
  1
  2
  300
  Index
  0
  20140409
  2
  3
  400
  Index
  1
  20140409
  3
  2
  500
  Content
  1
  20140409
  4
  4
  900
  Content
  0
  20140409
  5
  3
  200
  Content
  1
  20140409
  语句:
  SELECTCOUNT(distinct uid) as num,COUNT(1) as people,SUM(case when status=1then money end) as total group by date,page

页: [1]
查看完整版本: MYSQL中分类汇总