gpt4 book ai didi

sql - 我的 SqlCode 中的逻辑错误

转载 作者:行者123 更新时间:2023-12-04 19:24:56 28 4
gpt4 key购买 nike

我需要运行一个报告,给出每个月具有特定创建者的记录数。对于每个月,我的查询不止一次显示该月。难道是我做错了什么:我的脚本:

Select DATEPART(mm,DatePrinted),COUNT(ReceiptNo)As CardPrinted
from mytble where ReceiptNo like'990%'
Group by DatePrinted

可能的收据:800,75。
我希望是这样的:

一月总数

2 月总数等

最佳答案

使用Group by DATEPART(month,DatePrinted)

Select DATEPART(month,DatePrinted) As MyMonth, COUNT(ReceiptNo) As CardPrinted
From mytble
Where ReceiptNo like '990%'
Group by DATEPART(month,DatePrinted)

如果您需要月份名称,请使用 DATENAME() 函数:

Select DATENAME(month,DatePrinted) As MyMonth, COUNT(ReceiptNo) As CardPrinted
From mytble
Where ReceiptNo like '990%'
Group by DATENAME(month,DatePrinted)

注意:您可能需要按年份分组才能获得正确的结果。否则,无论年份如何,您都会得到类似月份的计数。如果您要查找特定年份,请将此过滤器添加到 WHERE 子句 Year(DatePrinted) = yourYear

关于sql - 我的 SqlCode 中的逻辑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19980900/

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