求一MySql语句 需求:1 12 13 24 25 26 37 38 39 3结果1 12 11 22 23 21 32 33 34 3要求:能在MySql中运行 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select (select count(1)+1 from tb where col2=t.col2 and col1<t.col1) as col1, col2from tb t 标准SQL基本上都支持的。mysql> select * from t_GG_wg;+----+------+| id | fld |+----+------+| 1 | 1 || 2 | 1 || 3 | 2 || 4 | 2 || 5 | 2 || 6 | 3 || 7 | 3 || 8 | 3 || 9 | 3 |+----+------+9 rows in set (0.00 sec)mysql> select count(*),a.fld -> from t_GG_wg a ,t_GG_wg b -> where a.fld=b.fld -> and a.id>=b.id -> group by a.id -> order by a.id;+----------+------+| count(*) | fld |+----------+------+| 1 | 1 || 2 | 1 || 1 | 2 || 2 | 2 || 3 | 2 || 1 | 3 || 2 | 3 || 3 | 3 || 4 | 3 |+----------+------+9 rows in set (0.00 sec)mysql> mysql> select * from e;+----+------+| id | t |+----+------+| 1 | 1 || 2 | 1 || 3 | 2 || 4 | 2 || 5 | 2 || 6 | 3 || 7 | 3 || 8 | 3 || 9 | 3 |+----+------+9 rows in set (0.00 sec)mysql> select count(1) cc,e.t tt from e,e ee where e.id<=ee.id and e.t=ee.t group by e.id order by tt,cc;+----+------+| cc | tt |+----+------+| 1 | 1 || 2 | 1 || 1 | 2 || 2 | 2 || 3 | 2 || 1 | 3 || 2 | 3 || 3 | 3 || 4 | 3 |+----+------+9 rows in set (0.01 sec) 这个语法在别的数据库里面不支持吧?group by 列 怎么聚合函数怎么转换成hql语言啊 请教SQL语句的一个问题。纠结了, 存储过程的问题? 主从同步中load data from master的问题! windows下的增量备份 如何把group by后的结果分着列出来? 求ado 连接 Postgresql (加急) 我导入数据老是说找不到文件,不知道为什么? 关于mysql字符集编码的问题,很急啊,大虾们 jdbc 如何访问 linux 下mysql sql语句在mysql cluster执行时间过长? 1064 1054错误, Unknown column 怎么办? AS 别名 出错。 MySQL Function的问题
(select count(1)+1 from tb where col2=t.col2 and col1<t.col1) as col1,
col2
from
tb t
+----+------+
| id | fld |
+----+------+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |
| 5 | 2 |
| 6 | 3 |
| 7 | 3 |
| 8 | 3 |
| 9 | 3 |
+----+------+
9 rows in set (0.00 sec)mysql> select count(*),a.fld
-> from t_GG_wg a ,t_GG_wg b
-> where a.fld=b.fld
-> and a.id>=b.id
-> group by a.id
-> order by a.id;
+----------+------+
| count(*) | fld |
+----------+------+
| 1 | 1 |
| 2 | 1 |
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
| 1 | 3 |
| 2 | 3 |
| 3 | 3 |
| 4 | 3 |
+----------+------+
9 rows in set (0.00 sec)mysql>
+----+------+
| id | t |
+----+------+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |
| 5 | 2 |
| 6 | 3 |
| 7 | 3 |
| 8 | 3 |
| 9 | 3 |
+----+------+
9 rows in set (0.00 sec)mysql> select count(1) cc,e.t tt from e,e ee where e.id<=ee.id and e.t=ee.t grou
p by e.id order by tt,cc;
+----+------+
| cc | tt |
+----+------+
| 1 | 1 |
| 2 | 1 |
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
| 1 | 3 |
| 2 | 3 |
| 3 | 3 |
| 4 | 3 |
+----+------+
9 rows in set (0.01 sec)
group by 列