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
相关问答:
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
有TABLEA 字段为 采购单号、行号、物料编码、入库日期
现想按照物料编码查询最大入库日期
语句如下:
SELECT 采购单号、行号、物料编码、入库日期 from TABLEA A WHERE 入库日期=(SELECT MAX(入库日期 ......
原SQL语句SQL code:
SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......
现在有一个部门表dept(部门名称,部门号。。)有一个人员表emp(姓名,人员编号,职位,薪资,部门)
emp表中的内容是这样的:
a 1 工程师 3000 软件部
b 2 普通员工 2000 硬件部
c 3 工程师 4000 硬件部
d ......