mysql的group by ,order by语句的使用
发布日期:2021-05-10 08:31:17 浏览次数:10 分类:精选文章

本文共 2157 字,大约阅读时间需要 7 分钟。

������������������������������������������������������������������

���������������������������������������������������������������������������������uin���������������������������������������������������������������������

���������������������main_table���������fd_sendprize_log������������������zone_id���uin���������������������������������������������������������������������������������������SQL���������������

$sql = "select uin, zone_id, count(*) as count, sum(money) as totalMoney
from fd_sendprize_log
group by zone_id, uin";

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������������������������������������������������������������������

$sql2 = "select uin, zone_id, max(count) as maxTimes
from (
select uin, zone_id, count(*) as totalCount, sum(money) as totalMoney
from fd_sendprize_log
group by zone_id, uin
) as A
group by zone_id
order by maxTimes desc";

������������������������������������������������������������������������������

$sql3 = "select uin, zone_id, max(totalMoney) as maxMoney
from (
select uin, zone_id, count(*) as totalCount, sum(money) as totalMoney
from fd_sendprize_log
group by zone_id, uin
) as A
group by zone_id
order by maxMoney desc";

���������������������������������PHP���������������������������������������������������������������������������������

$zoneCount = $this->model->query_sqls($sql2); // ������������������������������������������
$zoneMoney = $this->model->query_sqls($sql3); // ������������������������������������������

���������������

  • ������������������fd_sendprize_log������������������������uin���zone_id���money������
  • ���������������������������������������������������
  • ���������������������������������������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:mysql中group by 和 group_concat()的区别
下一篇:安装walle后进行检测错误总出现的问题解决

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月04日 10时23分19秒