Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql StoredProcess中分配默认值_Mysql - Fatal编程技术网

如何在mysql StoredProcess中分配默认值

如何在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

如何在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;

错误代码:1242。子查询返回的行数超过1行。您可以使用示例数据创建SQLFIDLE吗?当我使用您的数据尝试使用SQL时,不会出现错误: