求一sql语句? - MS-SQL Server / 基础类
我有一视图表有usrcode和time, 同时另一个表有usrcode和usrguanid和usrtime
原则
从最近得time中插入数据(相等更好);
更新有数据的优先插入
view aa table bb
usrcode time usrcode usrguanid usrtime
20051617 201005171537 20051617 117.25 201005171236
20081918 201005181532 20081918 234.25 201005181532
20081318 201005161532 20081318 668.47 201005161235
20081319 201005161532 20081918 552.33 201005181555
20081320 201005161755 20081318 678.55 201005161555
20081318 668.47 201005191558
20081319 201005161533
20081319 345.88 201005181543
20081320 201005161750
解释一下规则
可以看到20081918在bb中有两条,用usrtime和time对比时间 第二条时间相等 留下,
20081318在bb中有3条,用usrtime和time对比时间 分别为201005161555, 201005161235,201005191558,而201005161555与201005161532最近 留下,
20081319就两条 虽然201005161533时间较近,但无数据,所以只有选201005181543时间远有数据的
通过上两个表我就得到视图表cc
usrcode usrguanid time
20051617
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......