地址是http://topic.csdn.net/u/20091124/16/e45dde93-eae6-4a8a-9015-0c44419bfdaa.html你给出的语句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;
功能是能实现的,不过速度太慢,表里面有50万条数据,,执行了12个小时,,都没有弄完。索引是有的所以,想请教一下你,还有不有其它的写法?
-> (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;
功能是能实现的,不过速度太慢,表里面有50万条数据,,执行了12个小时,,都没有弄完。索引是有的所以,想请教一下你,还有不有其它的写法?
解决方案 »
- isql问题
- 求一条从表a取得数据插入到表b命令
- 如何提高mysql 服务器图片存取速度
- MySQL4.0.16导出的文件,导入到另一台同版本数据库就导不进去了!!!
- mysql 中实现SET IDENTITY_INSERT tablename ON功能的语句怎么写?
- 求一条SQL语句
- 请教在MySQL中如何设置select_limit的值?
- 本地调试是http;//127.0.0.1:287,在网上为什么用我的ip代替127.0.0.1时看不到任何东西?
- MySql数据库报错 Truncated incorrect DOUBLE value
- win7 安装完成mysql5.6后,服务无法启动1067错误
- mysql 存储过程里的@是什么意思?加和不加有什么区别?
- select优化问题
无论是用 join 还是这种子查询都不会快。先看一下你的索引。可以建立两个索引以提高一下效率1. (id)
2. (col1)
select id,@col1:=ifnull(col1,@col1) as col1,col2 from t_fengchujun;mysql> select * from t_fengchujun;
+------+------+-------+
| 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> set @col1=null;
Query OK, 0 rows affected (0.00 sec)mysql> select id,@col1:=ifnull(col1,@col1) as col1,col2
-> from t_fengchujun;
+------+------+-------+
| 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.00 sec)mysql>
Execution Time : 00:00:01:250
Transfer Time : 00:00:01:109
Total Time : 00:00:02:359
一秒就搞定了。
你太牛了。。
有没有 存储过程 学习的资料,,,比如在 csdn的贴子什么的。想去学习一下。。能介绍一下吗?