求一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语言啊 mysql乱码问题 MYSQL 创建中文表名,以前好使,今天时而好使,时而不好使 在init_connect配置参数的时候,可以获取登录用户,那在退出的时候,也可以获取退出用户吗? 请问mysql4.0怎么升级为5.1版本呢? 数据库设计求助 求MYSQL 负载优化方案。 MySQL中查询和跟新碰到的问题,把我的数据库都弄乱了,请教该如何解决,谢谢! 两表查询的SQL问题 中国的技术专家问什么不改进MySQL mysql查询性能 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 列