i have tables this:
attendance(offering_id
,visitor_id, regstr_date,amount_paid) offer(offering_id
,teacher_id) teacher(teacher_id
,teacher_firstname,teacher_lastname,start_date)
it possible 1 visitor may attend twice or more. want retrieve visitor_id, regstr_date,total amount_paid,average amount_paid attendance offering id 30,40 or 50 , teacher's start date less visitor's latest regstr_date , average amount_paid per visitor less 600. code follows:
select distinct(a.visitor_id) v_id , max(a.regstr_date) reg_date, sum(a.amount_paid) total_pay, count(a.regstr_date) attendance_count, avg(a.amount_paid) average_paid attendance a, teacher t, offer o a.offering_id = o.offering_id , o.teacher_id = t.teacher_id , a.offering_id in ('30', '40', '50') , max(a.regstr_date) > t.start_date group a.visitor_id having avg (a.amount_paid) <= 600;
but shows group function not allowed here. if possible me please?
this query written ms-sql server
select a.visitor_id v_id , max(a.regstr_date) reg_date, sum(a.amount_paid) total_pay, count(a.regstr_date) attendance_count, avg(a.amount_paid) average_paid attendance inner join offer o on a.offering_id = o.offering_id inner join teacher t on t.teacher_id = o.teacher_id a.offering_id in('30','40','50') group a.visitor_id,t.start_date having avg (a.amount_paid)<=600 , max(a.regstr_date)>t.start_date;
Comments
Post a Comment