这是什么SQL查询? [英] What is the sql query for this?
本文介绍了这是什么SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Id Project_Id Activity_Time Username
1 100 2008-01-01 11:12:13 A
2 100 2008-01-01 00:00:00 B
3 500 2008-02-01 00:00:00 C
4 300 2008-02-03 00:00:00 D
5 500 2008-03-03 11:11:11 A
6 300 2008-04-04 00:00:00 D
7 500 2008-05-05 00:00:00 C
8 200 2008-06-06 00:00:00 D
9 100 2009-01-01 11:12:13 A
10 300 2010-01-01 01:02:03 A
根据以下输入选择 Project_Id 的sql查询是什么:
What is the sql query to select Project_Id based on following input :
- 对于给定的用户名
- 按Activity_Time排序-最新的
- 与众不同的Project_Id
- 仅10行
我尝试了几个查询,但没有任何效果,因此请在这里寻求帮助. 目前使用的是H2数据库,但是会在一段时间内发生变化.
I tried few queries nothing worked, so seeking help here. Currently H2 database is used but it would change over a period.
[更新]这是真正的项目要求,不是家庭作业,是新手,请不要取笑,要学习这些东西.
[Update] This is a true project requirement, not a home work, am a newbie, please don't make fun, am learning the stuffs.
推荐答案
如果不能完全正常工作,这应该是一个好的开始...
This should be a good start if not completely working ...
SELECT TOP 10
project_ID, max(activity_time) as activity_time
FROM
table_name
WHERE
username = usernameVariable
GROUP BY
project_id
ORDER BY
activity_time DESC
这篇关于这是什么SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文