sql返回活动的最后一条生成的所有订单,帮我写条查询语句
发布网友
发布时间:2022-04-11 17:57
我来回答
共2个回答
懂视网
时间:2022-04-11 22:18
/*增幅降幅排名*/
代码如下:
Select top 50 UserName,sum(ReceivePrice) - sum(GuessPrice) as ReceivePrice,
cast(sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / count(ReceivePrice) * 100 as numeric(4,1)) as Rate
From [game_FantasyLog]
WHERE IsJudge=1
GROUP BY UserId,UserName
ORDER BY sum(ReceivePrice) - sum(GuessPrice) ASC
/*正确率错误率排名*/
代码如下:
Select top 50 UserName,sum(ReceivePrice) - sum(GuessPrice) as ReceivePrice,
cast(sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / count(ReceivePrice) * 100 as numeric(4,1)) as Rate
From [game_FantasyLog]
WHERE IsJudge=1
GROUP BY UserId,UserName Having count(UserId) >= 5
ORDER BY cast(sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / count(ReceivePrice) * 100 as numeric(4,1)) ASC
/*大手笔排名*/
代码如下:
Select top 50 l.UserName,sum(l.GuessPrice),sum(l.ReceivePrice),f.title
From [game_FantasyLog] l left join [game_fantasy] f on l.topicid = f.id
GROUP BY l.TopicId,l.UserName,f.title
ORDER BY sum(l.GuessPrice) DESC
/*冷门场次排名*/
代码如下:
Select top 50 f.id,f.title,f.GuessPrice,(select sum(receivePrice) FROM [game_FantasyLog] l where l.topicid = f.id),
cast((select sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / f.GuessTimes FROM [game_FantasyLog] l2 where l2.topicid = f.id) as numeric(4,2))
From [game_Fantasy] f WHERE f.GuessPrice > 1000
ORDER BY (select sum(receivePrice) FROM [game_FantasyLog] l where l.topicid = f.id) ASC
/*冷门场次的命中者*/
代码如下:
Select top 50 UserName,sum(ReceivePrice) as ReceivePrice
From [game_FantasyLog] where topicid=29
GROUP BY TopicId,UserName
ORDER BY sum(ReceivePrice) DESC
热心网友
时间:2022-04-11 19:26
您好,这样的:
select top(1) * from table order by id desc 或者
select top(1) * from table where id=(select max(id) from table)
如果是查询最后一条被插入的记录,也借用达人的结论:
"除非指定了最后被插入记录的标识列,或者是ID,或者是插入时间.不然是没办法得到这条记录的."
原文:
If it is the last record inserted, there is no way to get that unless you have some field you maintain to allow you to find the last record inserted.
关于查询最后一条网上有好多帖子,要研究的话问题可多了....
不过我认为明确自己想要什么就行了,研究那些个太浪费脑细胞.加个ID字段最简单。