数据库统计查询

查询agentuid相同的数据 并安装agentuid的数目进行排行

select count(*) as total,agentuid from `ss_member` where agentuid>0 group by agentuid order by total desc limit 100

根据id号 查出其他字段的总额

第一种
select uid,sum(money) as moneytotal,sum(votes) as votestotal  from cmf_users_cashrecord group by uid
第二种
select uid,sum(money) as moneytotal,sum(votes) as votestotal  from cmf_users_cashrecord where uid=100
第三种(说明 将familyid 和uid相同的用户 以天为单位 将profit进行统计)
select uid,sum(profit) as profitzong from cmf_family_profit where familyid=100 group by uid,time desc


统计不同值下的数量

select sum(case when one_uid='10251' then 1 else 0 end) as one,sum(case when two_uid='10252' then 1 else 0 end) as two from xzb_users_agent

查询两个字段在不同条件下差的和

select
sum(case when bet_type=1 then coin else 0 end  - case when bet_type=1 then IFNULL(kick_conn,0) else 0 end) as one,
sum(case when bet_type=2 then coin else 0 end  - case when bet_type=2 then IFNULL(kick_conn,0) else 0 end) as two,
sum(case when bet_type=3 then coin else 0 end  - case when bet_type=3 then IFNULL(kick_conn,0) else 0 end) as three,
sum(case when bet_type=4 then coin else 0 end  - case when bet_type=4 then IFNULL(kick_conn,0) else 0 end) as four,
sum(case when bet_type=5 then coin else 0 end  - case when bet_type=5 then IFNULL(kick_conn,0) else 0 end) as five
from  cmf_users_game_bet
where  square_type=0


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值