如何在mysql StoredProcess中分配默认值
如何在MySQL存储过程中分配默认值如何在mysql StoredProcess中分配默认值,mysql,Mysql,如何在MySQL存储过程中分配默认值 DELIMITER $$ CREATE DEFINER=`ntc`@`%` PROCEDURE `MangerModule`() BEGIN select (select sum(AmountRecevied) from collection) as TotalAmount, (select @DayAmount := sum(AmountRecevied) as TotoalAmountperday
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;
错误代码:1242。子查询返回的行数超过1行。您可以使用示例数据创建SQLFIDLE吗?当我使用您的数据尝试使用SQL时,不会出现错误: