how to Update table Sales_summary with max(sales) data from
table sales_dataTable 1. sales_data table Table 2.
Sales_summary

Region sales Region sales
N 500 N 0
N 800 W 0
N 600
W 899
W 458
W 900

I want the Sales_summary After Update like this
Region Sales
N 800
W 900


Answer Posted / sunil

-- It can be done by simple procedure


DELIMITER $$
drop procedure if exists updatesale$$
create procedure updatesale()
BEGIN
declare l_loop_end INT default 0;
declare l_region varchar(10);
declare l_sale int ;

declare cur_1 cursor for select region 'Region',max(sales)
'SALES' from sales_data group by region;
declare continue handler for sqlstate '02000' set l_loop_end
= 1;

open cur_1;

repeat

fetch cur_1 into l_region,l_sale;

if not l_loop_end then
update sales_summery set sales=l_sale where region=l_region;
end if;
until l_loop_end end repeat;
close cur_1;
end$$
DELIMITER ;



call updatesale;

-- now check
select * From sales_summery;

region sales
w 900
N 800

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is time based sql injection?

569


What does select count (*) mean in sql?

632


What are the benefits of pl/sql packages?

636


how to implement one-to-one, one-to-many and many-to-many relationships while designing tables? : Sql dba

641


What is sql performance tuning?

570






What is audit logout in sql profiler?

670


Mention what does plv msg allows you to do?

764


Is big data nosql?

602


what is index? : Sql dba

651


What is the difference between inner join and outer join?

615


Can unique keys be null?

577


What is a record in a database?

657


How do I write a cron which will run a sql query and mail the results to agroup?

613


Can we declare a column having number data type and its scale is larger than pricesionex: column_name number(10,100),column_name numbaer(10,-84)

633


What is pls integer?

680