Mysql取相同数据最大的间隔数 字段名: time 和 stype表名:test按照time时间段筛选出stype最大间隔,这个语句怎么写?搞了一天了也没结果.比如图中,是 time>=2018-05-23 13:21:01 and time<=2018-05-23 14:30:43 来筛选的然后筛选出这个时间段,再筛选出 stype=1 的最大出现间隔, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mysql> select * from test;+---------------------+-------+| time | stype |+---------------------+-------+| 2018-05-23 13:21:01 | 2 || 2018-05-24 13:22:01 | 5 || 2018-05-25 13:23:01 | 3 || 2018-05-26 13:24:01 | 3 || 2018-05-27 13:25:01 | 1 || 2018-05-28 13:26:01 | 4 || 2018-05-29 13:27:01 | 3 || 2018-05-30 13:28:01 | 1 || 2018-05-31 13:29:01 | 1 || 2018-06-01 13:30:01 | 2 || 2018-06-02 13:31:01 | 5 || 2018-06-03 13:32:01 | 5 || 2018-06-04 13:33:01 | 2 || 2018-06-05 13:34:01 | 3 || 2018-06-06 13:35:01 | 4 || 2018-06-07 13:36:01 | 2 || 2018-06-08 13:37:01 | 2 || 2018-06-09 13:38:01 | 1 || 2018-06-10 13:39:01 | 5 || 2018-06-11 13:40:01 | 3 || 2018-06-12 13:41:01 | 3 || 2018-06-13 13:42:01 | 3 || 2018-06-14 13:43:01 | 1 || 2018-06-15 13:44:01 | 4 || 2018-06-16 13:45:01 | 2 || 2018-06-17 13:46:01 | 3 || 2018-06-18 13:47:01 | 2 || 2018-06-19 13:48:01 | 3 || 2018-06-20 13:49:01 | 4 || 2018-06-21 13:50:01 | 1 || 2018-06-22 13:51:01 | 3 || 2018-06-23 13:52:01 | 2 |+---------------------+-------+32 rows in set (0.00 sec)mysql> select max(i) -> from ( -> select time,stype, -> (select count(*) from test where time<=a.time) as cn, -> (select count(*) from test where time<=a.time)-@pcn as i, -> @pcn:=(select count(*) from test where time<=a.time) -> from test a -> where time>='2016-05-23 13:21:01' and time<='2019-05-23 14:30:43' -> and stype=1 -> ) t;+--------+| max(i) |+--------+| 9 |+--------+1 row in set (0.01 sec)mysql> 如果某一个stype,只出现了一次,并且是最后一条数据,应该算什么。 mysql安装后/etc/rc.d/init.d里面没有mysqld 关于两个表sum求和的问题,sql怎么写? MySQL乱码问题! 请教mysql报警声音如何去除? 这个连级触发器如何写? 请问如何书写SQL语句以实现如下功能? 问一个Sql语句 求高手帮我分析下mysql错误日志 mysql-proxy 读写分离,登录 从Mysql数据库服务器导出的sql文件,在本地导入时报错 MySQL能实现按分组计算相关系数吗? 想问各位大大 MySQL 是怎么做高可用的?
+---------------------+-------+
| time | stype |
+---------------------+-------+
| 2018-05-23 13:21:01 | 2 |
| 2018-05-24 13:22:01 | 5 |
| 2018-05-25 13:23:01 | 3 |
| 2018-05-26 13:24:01 | 3 |
| 2018-05-27 13:25:01 | 1 |
| 2018-05-28 13:26:01 | 4 |
| 2018-05-29 13:27:01 | 3 |
| 2018-05-30 13:28:01 | 1 |
| 2018-05-31 13:29:01 | 1 |
| 2018-06-01 13:30:01 | 2 |
| 2018-06-02 13:31:01 | 5 |
| 2018-06-03 13:32:01 | 5 |
| 2018-06-04 13:33:01 | 2 |
| 2018-06-05 13:34:01 | 3 |
| 2018-06-06 13:35:01 | 4 |
| 2018-06-07 13:36:01 | 2 |
| 2018-06-08 13:37:01 | 2 |
| 2018-06-09 13:38:01 | 1 |
| 2018-06-10 13:39:01 | 5 |
| 2018-06-11 13:40:01 | 3 |
| 2018-06-12 13:41:01 | 3 |
| 2018-06-13 13:42:01 | 3 |
| 2018-06-14 13:43:01 | 1 |
| 2018-06-15 13:44:01 | 4 |
| 2018-06-16 13:45:01 | 2 |
| 2018-06-17 13:46:01 | 3 |
| 2018-06-18 13:47:01 | 2 |
| 2018-06-19 13:48:01 | 3 |
| 2018-06-20 13:49:01 | 4 |
| 2018-06-21 13:50:01 | 1 |
| 2018-06-22 13:51:01 | 3 |
| 2018-06-23 13:52:01 | 2 |
+---------------------+-------+
32 rows in set (0.00 sec)mysql> select max(i)
-> from (
-> select time,stype,
-> (select count(*) from test where time<=a.time) as cn,
-> (select count(*) from test where time<=a.time)-@pcn as i,
-> @pcn:=(select count(*) from test where time<=a.time)
-> from test a
-> where time>='2016-05-23 13:21:01' and time<='2019-05-23 14:30:43'
-> and stype=1
-> ) t;
+--------+
| max(i) |
+--------+
| 9 |
+--------+
1 row in set (0.01 sec)mysql>