select @totalMoney =2 没有问题
select @totalMoney = SUM([count]*UnitPrice) from Cart inner join Books on Cart.BookId=Books.Id where Cart.UserId=@userId
那就是这条语句的条件有问题,改成
select @totalMoney = isnull(SUM([count]*UnitPrice),0) from Cart inner join Books on Cart.BookId=Books.Id where Cart.UserId=@userId
MySQL教程4 MySQL8运算符、函数、存储过程及新增数据类型 17.之创建带有IN和OUT参数的存储过程 学习猿地