Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query selecting Average < 650

Status
Not open for further replies.

wylliecoyote

Technical User
Feb 5, 2006
7
CA
I need a query that will select only those student IDs with an average amount_paid less than 650. So far I have this written out and it works for returning the data with the criteria given. What would I add to only select where the student_id is less than 650? I have been working on this for hours and can not figure it out.

Thanks.

Code:
select student_id as "StudentId", sum(amount_paid) as "Total_Paid",
min(regstrn_made_date) as "Earliest_Reg_Date",
count(*) as "Number_of_courses", avg(amount_paid) as "Average_Paid" from attendance
where offering_id in ('9111','9112','9212')
group by student_id
order by "Total_Paid" desc;
 
SELECT ..
FROM ...
WHERE ...
GROUP BY student_id
HAVING AVG(amount_paid) < 650
ORDER BY 2 DESC

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 


Hi,
Code:
select student_id as "StudentId"
, sum(amount_paid) as "Total_Paid"
,min(regstrn_made_date) as "Earliest_Reg_Date"
,count(*) as "Number_of_courses"
, avg(amount_paid) as "Average_Paid" 

from attendance

where offering_id in ('9111','9112','9212')

group by student_id
[b]
Having avg(amount_paid)<650
[/b]
order by "Total_Paid" desc;

Skip,

[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue]
 
Thank you so much! This works! I wish I would of asked this forum earlier, it would of saved me much grief!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top