易截截图软件、单文件、免安装、纯绿色、仅160KB

求一复杂sql语句 - MS-SQL Server / 基础类

id stucode stuaddress sturoom stutime
1 22 35# n502 201005  
2 22 35# n502 201007
3 12 45# n501 201005
4 22 35# n502 201005
5 22 35# n502 201005
6 12 45# n501 201009
7 12 65# n401 201010
8 22 35# n502 201005
9 22 34# n502 201005
10 32 35# n512 201005
11 22 34# n502 201007
12 32 55# n512 201009
13 33 55# n512 201009
求一sql语句得到结果如下:
code address room time
22 35# n502 201007
12 45# n501 201009
32 55# n512 201009
33 55# n512 201009

code为基础,然后对比address+room 把相同条目多的留下,最后只留下一条time最大的.

原则一:22的 35#+n502 有4条, 22的34#+n502 有2条 所以留下22的 35#+n502,然后再剩下时间最大的一条
22 35# n502 201007
原则二:32的55#+n512 有1条, 32的35#+n512有1条 留时间最大的一条,如果时间相同留id大的,id唯一  
32 55# n512 201009
ms sql 在my sql中报错 mysql怎么写? 以下为语句

with cte as(
select *
,count(stuaddress+sturoom) over(partition by stucode,stuaddress+sturoom) as cnt
,max(stutime) over(partition by stucode,stuaddress+sturoom) as mx_time
from #test)

select stucode,stuaddress,sturoom,stutime from cte a where stutime=mx_time
and not exists(select 1 from cte 
  where stutime=mx_time 
  and(( a.stucode=stucode and a.cnt=cnt and a.stutime<stutime) 
  or ( a.stucode=stucode and


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

数据以xml格式返回 - MS-SQL Server / 应用实例

从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
   <folder state="unchecked&qu ......

sql - MS-SQL Server / 疑难问题

sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊

随便搞一D版吧,

迅雷第一个就可以用
2000,2005都这样

http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......

请教SQL语句查询问题? - MS-SQL Server / 基础类

我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间  
  Id value state dattime  
  101 32.3 0 ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号