本文介绍了SQL查询查找,天气输入的记录是否是当天的第一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有一个表,其中包含UserID,日历日期和taskName作为列.请让我知道,从sql查询天气中,我们可以发现,对于用户ID,它是否是当天在表中输入的第一条记录.
Suppose we have a table with UserID ,Calendar date and taskName as columns. Please let me know that from sql Query weather we can find that for a user id is it the first record entered in the table on that day or not.
推荐答案
DECLARE @TODAY DATE
SET @TODAY = CONVERT(VARCHAR(10), GETDATE(), 111)
SELECT COUNT(*) FROM myTable WHERE Calendar >= @TODAY
如果为零,则从午夜开始没有任何条目.
[edit]更改了表名和列名-OriginalGriff [/edit]
If it is zero, then there are no entries since midnight.
[edit]Changed table and column names - OriginalGriff[/edit]
SELECT *
FROM TableName t1
WHERE UserId = <userid_goes_here>
AND CalendarDate >= CAST( GETDATE() AS DATE)
AND NOT EXISTS (SELECT 1
FROM TableName t2
WHERE t2.UserId = t1.UserId
AND t2.CalendarDate < t1.CalendarDate
AND t2.CalendarDate >= CAST( GETDATE() AS DATE))</userid_goes_here>
您可以将GETDATE替换为正确的日期.
You can replace the GETDATE with a proper date.
这篇关于SQL查询查找,天气输入的记录是否是当天的第一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!