--> 测试数据:[mb]
if object_id('[mb]') is not null drop table [mb]
go
create table [mb]([mbid] int,[mbsort] int,[mbpic] varchar(5),[mdid] int)
insert [mb]
select 1,2,'a.jpg',1 union all
select 2,-1,'b.jpg',1 union all
select 3,0,'c.jpg',1 union all
select 4,-2,'d.jpg',3 union all
select 5,5,'e.jpg',2 union all
select 6,2,'f.jpg',3 union all
select 7,1,'g.jpg',2 union all
select 8,0,'h.jpg',2 union all
select 9,0,'i.jpg',4
--> 测试数据:[md]
if object_id('[md]') is not null drop table [md]
go
create table [md]([mdid] int,[mdname] varchar(4))
insert [md]
select 1,'小马' union all
select 2,'群群' union all
select 3,'小张' union all
select 4,'阿力'--查找:相同mdid的,只显示一条数据,而这条数据是mbsort为最小的一条--做法1:
select *
from mb a
where exists(select 1
from (select mdid,min(mbsort) as mbsort
from mb
group by mdid
) b
where a.mbsort = b.mbsort
and a.mdid = b.mdid
)--做法2:
select * from mb a where mbsort = (select min(mbsort) from mb where mdid = a.mdid)--问题:做法1和做法2那个快一点?数据量增加时是否会有性能变化?
--另外怎么看懂执行计划,我打开了执行计划,但是不知道两个语句的执行计划怎么比较--第二个小问题:
select num_col,char_col
from #temp
order by 1 desc
order by 1 desc 是根据什么排序?
解决方案 »
- 求SQL语句
- fd_udt_id是什么数据类型
- where XXX and YYY
- 创建index 什么时候使用include?大家来说说,见者有份。
- 简单错误
- sql用户与登录名问题解答
- 关于时间的问题
- (高分求教!)SQL Server是否可以把一个表的结构和数据一起dump出来?急!
- 删除xp_cmdshell,提示服务器: 消息 3701,级别 11,状态 5,过程 sp_dropextendedproc,行 18 无法 除去 过程 'xp_cmdshell',因为它在系统目录中
- 反跟踪问题
- 各位大哥,大姐:为什么SQL2000安装不上呀!在线等……详细如下:
- 求好用的SQLSever2005 下载地址
order by 1 desc 是根据什么排序?
你可以查帮助,
按你查询的第一列排序
2.order by 1 descorder by 1,2 desc 如果这样说你牛明白了,先按第1列排序,然后按第2列