gpt4 book ai didi

sql - 选择一周的记录

转载 作者:行者123 更新时间:2023-12-02 22:06:34 24 4
gpt4 key购买 nike

我写了这个查询,给我当天的记录

SELECT EnquiryOwner,Count(uid) 
FROM EnquiryMaster
WHERE orgid = '" + orgid + "'
AND (DAY(date) = DAY(GETDATE())
AND MONTH(date) = MONTH(GETDATE())
AND YEAR(date) = YEAR(GETDATE()))
GROUP BY EnquiryOwner

我想选择本周的记录。如果我在星期二访问,我想要从前一个星期二到这个星期二的记录

最佳答案

You can use dateadd to determine the date of one week before.

例如喜欢

DAY(date)   = DATEADD(day,   -7, GETDATE()) AND    
MONTH(date) = DATEADD(month, -7, GETDATE()) AND
YEAR(date) = DATEADD(year, -7, GETDATE())

... WHERE date between DATEADD(DAY,-7,GETDATE()) and GETDATE()

另请参阅 date and time functions 的列表.

关于sql - 选择一周的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16028888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com