If the total purchase amount for the customer is <25000 , status= Silver, If the total purchase amount for the customer is between 25000 and 50000, status= Gold, If the total purchase amount for the customer is >50000 , status= Platinum. The Payment table:
Cust_number Check_No Payment_Date Amount
103 HQ336336 2004-10-19 6066.78
103 JM555205 2003-06-05 14571.44
103 OM314933 2004-12-18 1676.14
112 BO864823 2004-12-17 14191.12
112 HQ55022 2003-06-06 32641.98
112 ND748579 2004-08-20 33347.88
114 GG31455 2003-05-20 45864.03
114 MA765515 2004-12-15 82261.22
114 NP603840 2003-05-31 7565.08
This is what I’ve tried:
create function 'pur_stat'(cid int)
returns varchar(20)
begin
declare stat varchar(20);
case
select when amount<25000 then stat='silver'
when amount>=25000 and amount<=50000 then stat='gold'
else 'platinum'
end as stat
return stat
But I am getting error in the query, please help