gpt4 book ai didi

php - 获取开始日期到结束日期之间的日期,以 php 月份明智计数

转载 作者:行者123 更新时间:2023-11-29 20:56:25 25 4
gpt4 key购买 nike

在 php 中如何按月按月计算以下数据中的每个用户

SELECT * FROM sales_info WHERE assigned_dse_name IN ('ANBHAZHAGAN .') AND invoice_date BETWEEN '2016-01-01 00:00:00' AND '2016-06-01 23:59:59'

在想取数有

 month   count
01 0
02 0
03 5
04 3
05 7
06 4

如何使用拆分月份明智循环进行查询。

最佳答案

试试这个;)

SELECT `mouth`, sum(`count`) AS `count` 
FROM (
SELECT LPAD(MONTH(invoice_date), 2, '0') AS `month`, COUNT(1) as `count`
FROM sales_info
WHERE assigned_dse_name IN ('ANBHAZHAGAN .') AND invoice_date BETWEEN '2016-01-01 00:00:00' AND '2016-06-01 23:59:59'
GROUP BY MONTH(invoice_date)
UNION
SELECT LPAD(t.`month`, 2, '0') AS `month`, t.`count` FROM (
SELECT 1 AS `month`, 0 AS `count` UNION
SELECT 2 AS `month`, 0 AS `count` UNION
SELECT 3 AS `month`, 0 AS `count` UNION
SELECT 4 AS `month`, 0 AS `count` UNION
SELECT 5 AS `month`, 0 AS `count` UNION
SELECT 6 AS `month`, 0 AS `count` UNION
SELECT 7 AS `month`, 0 AS `count` UNION
SELECT 8 AS `month`, 0 AS `count` UNION
SELECT 9 AS `month`, 0 AS `count` UNION
SELECT 10 AS `month`, 0 AS `count` UNION
SELECT 11 AS `month`, 0 AS `count` UNION
SELECT 12 AS `month`, 0 AS `count`) t
WHERE t.`month` >= MONTH('2016-01-01 00:00:00') AND t.`month` <= MONTH('2016-06-01 23:59:59'))TMP
GROUP BY `month`
ORDER BY `month`

关于php - 获取开始日期到结束日期之间的日期,以 php 月份明智计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37589574/

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