数据库统计查询
来源:互联网 发布:李氏筋骨散淘宝 编辑:程序博客网 时间:2024/06/06 00:31
查询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
- 数据库查询统计
- 数据库统计查询
- 数据库分类统计、分组查询
- ThinkPHP 数据库操作 统计查询
- 数据库的查询与统计
- 数据库的组合查询和统计查询
- 提高ORACLE数据库的查询统计速度
- 提高ORACLE数据库的查询统计速度
- 查询数据库所有表并统计数量
- SQL Server 数据库的统计查询
- oracle数据库(统计函数和分组查询)
- 数据库查询之(Ⅱ)统计、分组(排序)查询
- SQL sever 数据库统计查询和组合查询
- 统计查询
- 统计查询
- 统计查询
- 提高ORACLE数据库的查询统计速度(转贴)
- 提高ORACLE数据库的查询统计速度(转)
- 八大排序算法
- 百练4015:邮箱验证题解
- python-pandas的基本用法11
- redis cluster中添加删除重分配节点例子
- Ride to office
- 数据库统计查询
- Unity3D游戏开发——塔防小游戏
- 1.8 试探法算法
- 落笔
- 放大镜效果
- 文件操作
- 域名的那些事
- java基础第三题 循环结构
- 基于置换和代换方法的灰度图像的加密