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
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
有TABLEA 字段为 采购单号、行号、物料编码、入库日期
现想按照物料编码查询最大入库日期
语句如下:
SELECT 采购单号、行号、物料编码、入库日期 from TABLEA A WHERE 入库日期=(SELECT MAX(入库日期 ......
有这样一条SQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......