gpt4 book ai didi

每月数据sql查询

转载 作者:行者123 更新时间:2023-12-02 03:45:09 24 4
gpt4 key购买 nike

我编写了这个查询,当我从下拉列表中选择一年时,它会提供所有 12 个月的所有 365 天的每日数据。

SELECT
YEAR(Date) AS [Year]
, MONTH(Date) AS [Month]
, COUNT(*) AS [Total]
FROM EnquiryMaster
WHERE EnquiryOwner = '" + enqowner + "'
AND DATEPART(yyyy, Date) = '" + year + "'
AND orgid = '" + orgid + "'
GROUP BY
YEAR(Date)
, MONTH(Date)

UNION ALL

SELECT
YEAR(Date) AS [Year]
, NULL
, COUNT(*)
FROM EnquiryMaster
WHERE EnquiryOwner = '" + enqowner + "'
AND DATEPART(yyyy, Date) = '" + year + "'
AND orgid = '" + orgid + "'
GROUP BY YEAR(Date)

我想编写一个查询来选择月份和年份并仅显示该月份的数据

最佳答案

我想这就是你想要的,假设我理解了这个问题

SELECT
DATEPART(yyyy, Date),
DATEPART(mm, Date),
COUNT(*) AS [Total]
FROM EnquiryMaster
GROUP BY
DATEPART(yyyy, Date),
DATEPART(mm, Date)
ORDER BY
DATEPART(yyyy, Date), DATEPART(mm, Date)

关于每月数据sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17540963/

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