求一SQL语句 - MS-SQL Server / 基础类
描述:
表中有若干字段,其中,主键为:
行号,编号,组别
列举数据:
标识 行号 编号 组别 ......
1 1 S001 1
2 2 S001 1
3 2 S001 2
4 2 S001 3
5 3 S001 1 .......
6 1 S002 1
先求一SQL语句实现 根据编号检索出其中对应的记录,
要求,当行号重复时,取组别最大者
如果检索编号为S001的记录,上述数据检索结果为:
标识 行号 编号 组别 ......
1 1 S001 1
4 2 S001 3
5 3 S001 1 .......
在线等,请高手指教
SQL code:
select
*
from
tb t
where
组别=(select max(组别) from tb where 行号=t.行号)
SQL code:
select * from tb t where not exists(select 1 from tb where 行号=t.行号 and 组别>t.组别)
SQL code:
select t.* from tb t where 组别 = (select max(组别) from tb where 行号 = t.行号)
select t.* from tb t wh
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......