gpt4 book ai didi

PHP Mysql SELECT 上个月和用户选择的月份数据

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

我想检索上个月的数据和我的组合框选择的月份日期

这是我的代码,该查询不起作用。我认为问题出在 INTERVEL 命令中。请帮助我正确使用 INTERVAL 1 MONTH。

 $result = mysql_query("SELECT manufacturer,model, SUM(replace(payment_one,',','')) as payment_one FROM table1 WHERE
YEAR(payment_one_date) = '$YYYY'- INTERVAL 1 MONTH AND
MONTH(payment_one_date) = '$MM'-INTERVAL 1 MONTH AND
payment_one_bank='CB'");

最佳答案

SELECT
manufacturer,
model,
SUM(replace(payment_one,',','')) payment_one
FROM table1
WHERE (
payment_one_date < '$YYYY-$MM-01 00:00:00' /* <-- can be incorrect for your field type */
AND payment_one_date >= ('$YYYY-$MM-01 00:00:00' - INTERVAL 1 MONTH)
) AND payment_one_bank='CB'

关于PHP Mysql SELECT 上个月和用户选择的月份数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40211292/

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