mysql group 陷阱
来源:互联网 发布:数据库持久化 编辑:程序博客网 时间:2024/05/16 01:36
mysql> SELECT -> sn,Clientsn,createdtime -> FROM -> ClientCashDetail -> WHERE -> createdTime < '2015-12-25 00:00:00' -> GROUP BY clientSn -> ORDER BY createdtime DESC;+-------+----------+---------------------+| sn | Clientsn | createdtime |+-------+----------+---------------------+| 20146 | 12904 | 2015-12-28 18:51:59 || 20143 | 501 | 2015-12-28 17:36:21 || 20141 | 1177 | 2015-12-28 17:12:55 || 20135 | 57 | 2015-12-28 16:47:43 || 20124 | 1407 | 2015-12-28 16:19:15 || 20108 | 12808 | 2015-12-28 16:05:52 || 20107 | 592 | 2015-12-28 16:05:33 || 20102 | 12738 | 2015-12-28 16:03:21 || 20094 | 1570 | 2015-12-28 15:59:33 || 20091 | 2102 | 2015-12-28 15:57:18 || 20086 | 1659 | 2015-12-28 15:50:31 || 20084 | 13006 | 2015-12-28 15:07:03 || 20083 | 512 | 2015-12-28 15:04:51 |mysql> select Clientsn ,count(*) from ClientCashDetail group by Clientsn order by count(*) ;| 12 | 100 || 392 | 100 || 253 | 105 || 605 | 105 || 55 | 107 || 22 | 109 || 592 | 110 || 65 | 110 || 31 | 112 || 71 | 113 || 57 | 118 || 127 | 123 || 1 | 127 || 45 | 140 || 351 | 156 || 15 | 160 || 13 | 187 || 1123 | 198 |+----------+----------+1075 rows in set (0.00 sec)mysql> select sn,Clientsn,createdtime from ClientCashDetail where createdTime >= '2015-12-24 00:00:00' and Clientsn=1123;+-------+----------+---------------------+| sn | Clientsn | createdtime |+-------+----------+---------------------+| 19951 | 1123 | 2015-12-24 14:36:20 || 19995 | 1123 | 2015-12-24 15:11:59 || 19996 | 1123 | 2015-12-24 15:19:45 || 20118 | 1123 | 2015-12-28 16:09:24 |+-------+----------+---------------------+4 rows in set (0.00 sec)mysql> select sn,Clientsn,createdtime from ClientCashDetail where createdTime >= '2015-12-24 00:00:00' and Clientsn=1123 group by Clientsn;+-------+----------+---------------------+| sn | Clientsn | createdtime |+-------+----------+---------------------+| 19951 | 1123 | 2015-12-24 14:36:20 |+-------+----------+---------------------+1 row in set (0.00 sec)mysql> select sn,Clientsn,createdtime from ClientCashDetail where createdTime >= '2015-12-24 00:00:00' and Clientsn=1123 group by Clientsn order by createdtime desc;+-------+----------+---------------------+| sn | Clientsn | createdtime |+-------+----------+---------------------+| 19951 | 1123 | 2015-12-24 14:36:20 |+-------+----------+---------------------+1 row in set (0.00 sec)-------------------------------------------------------------------------------------------------------------------------------------------------------------------mysql> select sn,Clientsn,createdtime from ClientCashDetail where createdTime >= '2015-12-24 00:00:00' and Clientsn=1123 ;+-------+----------+---------------------+| sn | Clientsn | createdtime |+-------+----------+---------------------+| 19951 | 1123 | 2015-12-24 14:36:20 || 19995 | 1123 | 2015-12-24 15:11:59 || 19996 | 1123 | 2015-12-24 15:19:45 || 20118 | 1123 | 2015-12-28 16:09:24 |+-------+----------+---------------------+4 rows in set (0.00 sec)mysql> select max(sn),Clientsn,max(createdtime) from ClientCashDetail where createdTime >= '2015-12-24 00:00:00' and Clientsn=1123 group by Clientsn ;+---------+----------+---------------------+| max(sn) | Clientsn | max(createdtime) |+---------+----------+---------------------+| 20118 | 1123 | 2015-12-28 16:09:24 |+---------+----------+---------------------+1 row in set (0.00 sec)| 12825 | 2015-12-24 12:05:53 || 12861 | 2015-12-24 11:49:03 || 12899 | 2015-12-24 09:12:15 || 12904 | 2015-12-28 19:00:04 || 12914 | 2015-12-25 13:53:19 || 12941 | 2015-12-26 01:57:16 || 13004 | 2015-12-28 10:08:04 || 13006 | 2015-12-28 16:06:18 |+----------+---------------------+1075 rows in set (0.00 sec)mysql> select ClientSn, max(createdtime) from ClientCashDetail group by ClientSn;select SUM(accountBalance) from ( SELECT a.*FROM ClientCashDetail a INNER JOIN (SELECT MAX(createdtime) AS mtime FROM ClientCashDetail where createdTime < '2015-12-25 00:00:00' GROUP BY ClientSn) b ON a.createdtime = b.mtime) c
0 0
- mysql group 陷阱
- MySQL Group By 数据分组-- 陷阱
- 困在MySQL的Group by陷阱中两天
- mysql陷阱
- MySQL陷阱
- Hive.GROUP BY子句的“陷阱”
- 注意count时候group by 陷阱
- mysql inet_aton的“陷阱”
- mysql inet_aton的“陷阱”
- mysql中的group by
- mysql group by
- mysql中的group by
- Mysql 的 Group by
- mysql group by优化
- mysql group by 原理
- Mysql值group by
- Mysql group by 详解
- mysql group by用法
- 表、栈和队列
- Hbase存储详解
- Json---基础概念
- 深入浅出SFINAE
- 局部边缘保持滤波(LEP)高动态范围图像HDR压缩 matlab程序(一)
- mysql group 陷阱
- 求助,想用eclipse写个疏散的代码,但是有些写不出来,求补充
- LINQ排序,用order by 子句进行排序
- hdu 1004 Let the Balloon Rise 字典树
- apache 使用 mod_fcgid.so模块时 配置指令
- JVM内存分析以及Jconsole(二)
- 设置导航栏的背景颜色和字体
- 智能家居网络系统的设计(一)
- 【LVL1_5_c】【思考题】【7】char *p1="hellow world"和char p2[]="hellow world"的区别