Help Me:Can we select sum of 2 columns in one select statement?
-
Good morning freinds, i m trying to create following procedure in mysql5.0 but getting error abt check syntax in sql statement on 2nd column i.e. at sum(Tuesday). Monday & Tuesday are two columns of which i wnt to display sum of all records of Monday & tuesday so i wrote following procedure but Error??:sigh: As I tried already, i selected sum of other 2 columns at a time in one select stmt, but it is also giving error at 2nd column. In simple query i can select sum of more than one columns but why not in procedure? Anybody please help me following is the my procedure.----> DELIMITER $$ DROP PROCEDURE IF EXISTS `timesheet`.`sp_select` $$ CREATE PROCEDURE `sp_select`() BEGIN DECLARE mon,tue double; SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; SELECT mon,tue; END $$ DELIMITER ; What should i change in it to run properly. Please Reply Soon.:sigh: Thanx. -Regards Priya.
"The Difficult i can do it now... The Impossible will take a little longer."
-
Good morning freinds, i m trying to create following procedure in mysql5.0 but getting error abt check syntax in sql statement on 2nd column i.e. at sum(Tuesday). Monday & Tuesday are two columns of which i wnt to display sum of all records of Monday & tuesday so i wrote following procedure but Error??:sigh: As I tried already, i selected sum of other 2 columns at a time in one select stmt, but it is also giving error at 2nd column. In simple query i can select sum of more than one columns but why not in procedure? Anybody please help me following is the my procedure.----> DELIMITER $$ DROP PROCEDURE IF EXISTS `timesheet`.`sp_select` $$ CREATE PROCEDURE `sp_select`() BEGIN DECLARE mon,tue double; SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; SELECT mon,tue; END $$ DELIMITER ; What should i change in it to run properly. Please Reply Soon.:sigh: Thanx. -Regards Priya.
"The Difficult i can do it now... The Impossible will take a little longer."
SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; I haven't run this query and tested May be this could be the reason: sum(Monday) into mon - variable mon has been assigned sum(Tuesday) as tue - It is pseudo column won't that be sum(Tuesday) into tue
-
Good morning freinds, i m trying to create following procedure in mysql5.0 but getting error abt check syntax in sql statement on 2nd column i.e. at sum(Tuesday). Monday & Tuesday are two columns of which i wnt to display sum of all records of Monday & tuesday so i wrote following procedure but Error??:sigh: As I tried already, i selected sum of other 2 columns at a time in one select stmt, but it is also giving error at 2nd column. In simple query i can select sum of more than one columns but why not in procedure? Anybody please help me following is the my procedure.----> DELIMITER $$ DROP PROCEDURE IF EXISTS `timesheet`.`sp_select` $$ CREATE PROCEDURE `sp_select`() BEGIN DECLARE mon,tue double; SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; SELECT mon,tue; END $$ DELIMITER ; What should i change in it to run properly. Please Reply Soon.:sigh: Thanx. -Regards Priya.
"The Difficult i can do it now... The Impossible will take a little longer."
hai priya, you have not added Group by keyword in that, is that may be problem? using aggregate functions without groupby may also create problems. change that and try... Cheers asithangae
-
hai priya, you have not added Group by keyword in that, is that may be problem? using aggregate functions without groupby may also create problems. change that and try... Cheers asithangae
hai, check this it works for you...
declare @mon decimal declare @tue decimal select @mon = sum(ContactID), @tue = sum(ManagerID) from Employee select @mon,@tue
cheers asithangae