| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 718 人关注过本帖
标题:sql 语句 那位高手教下!!!
只看楼主 加入收藏
yuwenxiang
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2008-3-24
收藏
 问题点数:0 回复次数:1 
sql 语句 那位高手教下!!!
首先建表
create table tb(name varchar(10),val int,memo varchar(20))
insert into tb values('a',    2,   'a2(a的第二个值)')
insert into tb values('a',    1,   'a1--a的第一个值')
insert into tb values('a',    3,   'a3:a的第三个值')
insert into tb values('b',    1,   'b1--b的第一个值')
insert into tb values('b',    3,   'b3:b的第三个值')
insert into tb values('b',    2,   'b2b2b2b2')
insert into tb values('b',    4,   'b4b4')
insert into tb values('b',    5,   'b5b5b5b5b5')

在这表里面用sql语句查询
select a.* from tb a where not exists(select 1 from tb where name = a.name and val > a.val)
这里面的 1 是什么意思
select a.* from tb a where 1 > (select count(*) from tb where name = a.name and val > a.val ) order by a.name
也是 1 的问题
select a.* from tb a where not exists(select 1 from tb where name = a.name and val < a.val)


select a.* from tb a where val = (select top 1 val from tb where name = a.name order by newid()) order by a.name
这里面的newid()) 函数什么意思  怎么用
搜索更多相关主题的帖子: sql 语句 
2008-03-26 22:01
luyihuaa5201
Rank: 2
等 级:论坛游民
帖 子:254
专家分:10
注 册:2007-3-25
收藏
得分:0 
select a.* from tb a where not exists(select 1 from tb where name = a.name and val > a.val)    1和*是一样的!
2008-03-27 16:29
快速回复:sql 语句 那位高手教下!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014239 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved