gpt4 book ai didi

mysql - 如何在mysql存储过程中分配默认值

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

如何在 MySQL 的存储过程中分配默认值

DELIMITER $$

CREATE DEFINER=`ntc`@`%` PROCEDURE `MangerModule`()
BEGIN
select (select sum(AmountRecevied) from collection) as TotalAmount,
(select @DayAmount := sum(AmountRecevied) as TotoalAmountperday
from collection
where day(Date_Time)= day(CURRENT_DATE())) as Dayamount,

(select @MonthAmount :=sum(AmountRecevied) as TotoalAmountperMonth
from collection
where date_time between DATE_FORMAT(NOW() ,'%Y-%m-01')
and LAST_DAY(now() - interval 0 month )) as monthamount,

(select @YearAmount := sum(AmountRecevied) as TotoalAmountperYear
from collection
where year(Date_Time) =YEAR(CURRENT_DATE())) as yearamount;

END

最佳答案

使用IFNULL:

select (select IFNULL(sum(AmountRecevied), 0.0) from collection) as TotalAmount,
(select @DayAmount := IFNULL(sum(AmountRecevied), 0.0) as TotoalAmountperday
from collection
where day(Date_Time)= day(CURRENT_DATE())) as Dayamount,

(select @MonthAmount := IFNULL(sum(AmountRecevied), 0.0) as TotoalAmountperMonth
from collection
where date_time between DATE_FORMAT(NOW() ,'%Y-%m-01')
and LAST_DAY(now() - interval 0 month )) as monthamount,

(select @YearAmount := IFNULL(sum(AmountRecevied), 0.0) as TotoalAmountperYear
from collection
where year(Date_Time) =YEAR(CURRENT_DATE())) as yearamount;

关于mysql - 如何在mysql存储过程中分配默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23927853/

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