sql查询不重复 - MS-SQL Server / 疑难问题
regInfo 注册表
MemberId regDate
10001 2010-5-1
10002 2010-5-2
10003 2010-5-3
10004 2010-5-4
10005 2010-5-5
UserRecord 充值记录表
MemberId money dates
10001 5.00 2010-5-5
10002 10.00 2010-5-5
10001 15.00 2010-5-6
10003 5.00 2010-5-6
10001 10.00 2010-5-7
10004 20.00 2010-5-7
查询当月 注册的会员充值10元以上的记录。只保留第一条充值金额大于10的记录 要求显示结果
10001 15.00 2010-5-6
10002 10.00 2010-5-5
10004 20.00 2010-5-7
这个怎么写啊
SQL code:
select t.* from UserRecord t , MemberId n where t.MemberId = n.MemberId and datediff(mm,n.regDate,getdate()) = 0 and t.money > 10 and t.money = (select top 1 money from UserRecord where money > 10 and MemberId = t.MemberId)
SQL code:
[del]select b.MemberId,max(A.money),min(dates) as FirstDay as MonthMoney from UserRecord a inner join regInfo b on a.MemberId=b.MemberId
where month(a.dates)=month(getdate()) group by a.MemberId
having max(A.money)>10[/del]
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighte
相关问答:
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......
我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......
原SQL语句SQL code:
SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......