select a=m from table1 where id=1;
中 a=m是干什么用的? Result:
19 of 20
95%
You can be proud of yourself!
Time Spent
4:26
居然错了一个,也不知道是哪个错的:L 原帖由 xblues 于 15-6-2009 18:57 发表 http://www.freeoz.org/forum/images/common/back.gif
SQL语句分两种,一种是数据操作语句 DML,一种是数据定义语句 DDL
SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).
The query and update c ...
资料不全哦,DML DDL
还有个DCL呢? 说实话,这东西最近两年我一直都在用,不过每次用还是要查一下。总是记不住。
我对编程语言很少记,一般都是用哪种语言就现查。
回复 #15 xblues 的帖子
借此宝地,探讨一下有关left/right join应该如何优化索引,比如FreeOZ的SQL经常要执行类似下面这种SQL语句,大家看看如何建索引最好:SELECT p.subject AS re_subject, p.message,t.* FROM cdb_threads t LEFT JOIN cdb_posts p ON (t.tid=p.tid AND t.lastpost=p.dateline)
WHERE t.fid IN (7053, 200, 7033, 7062, 7061, 7036, 7035, 7067)AND t.displayorder IN (0)
ORDER BY t.lastpost DESC
LIMIT 25798, 30;
噩梦,永远的噩梦。:funk: 原帖由 ubuntuhk 于 15-6-2009 21:18 发表 http://www.freeoz.org/forum/images/common/back.gif
SELECT p.subject AS re_subject, p.message,t.* FROM cdb_threads t LEFT JOIN cdb_posts p ON (t.tid=p.tid AND t.lastpost=p.dateline)
WHERE t.fid IN (7053, 200, 7033, 7062, 7061, 7036, 7035, 7067)AND t.displayorder IN (0)
ORDER BY t.lastpost DESC
LIMIT 25798, 30;
索引好办,不过我觉得这个查询应该这样写
SELECT p.subject AS re_subject, p.message,t.* FROM (select * from cdb_threadsWHERE t.fid IN (7053, 200, 7033, 7062, 7061, 7036, 7035, 7067)AND t.displayorder IN (0)ORDER BY t.lastpost DESC) t LEFT JOIN cdb_posts p ON (t.tid=p.tid AND t.lastpost=p.dateline)LIMIT 25798, 30;
这样如果cdb_threads很大的话,一般会先得到一个较小的结果集,然后再用这个小的临时表LEFT JOIN (LEFT JOIN很费资源的), 这是我n年前用ORACLE的经验,Mysql和现在的ORACLE能否自动优化这个查询不好说。一般而言用ORACLE的话会先看看实际的SQL执行计划是什么样的,在决定如何优化。
页:
[1]
2