如 有表
id 字段1 字段21 a
2 fsf
3 fe
4 ggvbc
5 fsdf
6 fd
7 fsdf
8 b
9 kjf
10 jty
11 jty
12 ty
13 c
14 kyutj
15 jty
16 d
17 hfsh
18 berea 下面的内容 就是 与a 有关的,b 下面的内容是与b 有关的
所以我需要得到的是这样的
id 字段1 字段2
1 a
2 a fsf
3 a fe
4 a ggvbc
5 a fsdf
6 a fd
7 a fsdf
8 b
9 b kjf
10 b jty
11 b jty
12 b ty
13 c
14 c kyutj
15 c jty
16 d
17 d hfsh
18 d bere哪位大侠帮帮忙
id 字段1 字段21 a
2 fsf
3 fe
4 ggvbc
5 fsdf
6 fd
7 fsdf
8 b
9 kjf
10 jty
11 jty
12 ty
13 c
14 kyutj
15 jty
16 d
17 hfsh
18 berea 下面的内容 就是 与a 有关的,b 下面的内容是与b 有关的
所以我需要得到的是这样的
id 字段1 字段2
1 a
2 a fsf
3 a fe
4 a ggvbc
5 a fsdf
6 a fd
7 a fsdf
8 b
9 b kjf
10 b jty
11 b jty
12 b ty
13 c
14 c kyutj
15 c jty
16 d
17 d hfsh
18 d bere哪位大侠帮帮忙
解决方案 »
- mysql的存储过程(sp)中是否支持for循环
- MY-SQL 急救???
- my sql语法问题
- 怎样将一个表的integer类型字段改成serial类型?
- 会MYSQL全文检索的进来帮忙
- 求助:PostgreSQL数据库的数据库大小限制问题
- 请问怎样在Windows和Linux下访问远程(inter网)MySQL服务?
- redhat7.1下默认安装MYSQL
- MYSQL资源自动回收的问题!
- 按服务单号分组。显示出每组中时间最大的。网上的子查询什么的达不到效果。。
- java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transa
- 关于mysql_stmt_send_long_data 出现2035的问题
+------+------+-------+
| id | col1 | col2 |
+------+------+-------+
| 1 | a | NULL |
| 2 | NULL | fsf |
| 3 | NULL | fe |
| 4 | NULL | ggvbc |
| 5 | NULL | fsdf |
| 6 | NULL | fd |
| 7 | NULL | fsdf |
| 8 | b | NULL |
| 9 | NULL | kjf |
| 10 | NULL | jty |
| 11 | NULL | jty |
| 12 | NULL | ty |
| 13 | c | NULL |
| 14 | NULL | kyutj |
| 15 | NULL | jty |
| 16 | d | NULL |
| 17 | NULL | hfsh |
| 18 | NULL | bere |
+------+------+-------+
18 rows in set (0.00 sec)mysql> select id,
-> (select col1 from t_fengchujun where id=(select max(id) from t_fengchujun where id<=a.id and col1 is not null)) as col1,
-> col2
-> from t_fengchujun a;
+------+------+-------+
| id | col1 | col2 |
+------+------+-------+
| 1 | a | NULL |
| 2 | a | fsf |
| 3 | a | fe |
| 4 | a | ggvbc |
| 5 | a | fsdf |
| 6 | a | fd |
| 7 | a | fsdf |
| 8 | b | NULL |
| 9 | b | kjf |
| 10 | b | jty |
| 11 | b | jty |
| 12 | b | ty |
| 13 | c | NULL |
| 14 | c | kyutj |
| 15 | c | jty |
| 16 | d | NULL |
| 17 | d | hfsh |
| 18 | d | bere |
+------+------+-------+
18 rows in set (0.01 sec)mysql>
SELECT t1.id,t2.field1,t1.字段2 FROM tablename t1 INNER JOIN
(SELECT id,字段1 field1 FROM tablename WHERE length(字段1)=1) t2
WHERE t1.id<=t2.id;
SELECT t1.id,t2.field1,t1.字段2 FROM tablename t1 INNER JOIN
(SELECT id,字段1 field1 FROM tablename WHERE length(字段1)=1) t2
ON t1.id<=t2.id;
选出 id=(select max(id) from t_fengchujun where id<=a.id and col1 is not null) 的记录的col1值
选出比当前记录a.id小的最大的id, select max(id) from t_fengchujun where id<=a.id and col1 is not null