473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Damn sql problem again(sorry!)

I am currently working on an sql query to find employees which handled more orders than average in a certain half year. For arguments sake the half year is august-dec1997. I will use two queries, one to calculate COUNT and one for the avg:

So far I have the COUNT query sorted:

SELECT Employees.EmployeeID, Count(Orders.EmployeeID) AS CountOfOrders
FROM Employees, Orders
WHERE (((Employees.EmployeeID)=[Orders].[EmployeeID]))
GROUP BY Employees.EmployeeID;



However, I am uncertain how to proceed from here and find the >AVG part of this query. I know it would be something like this:

SELECT qrycountOfOrders.EmployeeID, Employees.FirstName, Employees.LastName, qrycountOfOrders.CountOfOrders,
FROM qrycountOfOrders, Employees
WHERE qrycountOfOrders.EmployeeID = Employees.EmployeeID;


Any help would be appreciated- thankyou!
Oct 17 '06 #1
4 1298
MMcCarthy
14,534 Expert Mod 8TB
Is this SQL query in Access?



I am currently working on an sql query to find employees which handled more orders than average in a certain half year. For arguments sake the half year is august-dec1997. I will use two queries, one to calculate COUNT and one for the avg:

So far I have the COUNT query sorted:

SELECT Employees.EmployeeID, Count(Orders.EmployeeID) AS CountOfOrders
FROM Employees, Orders
WHERE (((Employees.EmployeeID)=[Orders].[EmployeeID]))
GROUP BY Employees.EmployeeID;



However, I am uncertain how to proceed from here and find the >AVG part of this query. I know it would be something like this:

SELECT qrycountOfOrders.EmployeeID, Employees.FirstName, Employees.LastName, qrycountOfOrders.CountOfOrders,
FROM qrycountOfOrders, Employees
WHERE qrycountOfOrders.EmployeeID = Employees.EmployeeID;


Any help would be appreciated- thankyou!
Oct 17 '06 #2
Sorry yes it is in Access I completely forgot to say that!
Oct 17 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
This will give you the average:

SELECT Avg(qrycountOfOrders.CountOfOrders) AS AvgOfCountOfOrders
FROM qrycountOfOrders;

The easiest thing to do would be to establish this result as a control on a form. For this example lets call the form AverageOrders and the control AverageCount.

SELECT qrycountOfOrders.EmployeeID, Employees.FirstName, Employees.LastName, qrycountOfOrders.CountOfOrders,
FROM qrycountOfOrders, Employees
WHERE qrycountOfOrders.EmployeeID = Employees.EmployeeID
AND qrycountOfOrders.CountOfOrders > [Forms]![AverageOrders]![AverageCount];

I am currently working on an sql query to find employees which handled more orders than average in a certain half year. For arguments sake the half year is august-dec1997. I will use two queries, one to calculate COUNT and one for the avg:

So far I have the COUNT query sorted:

SELECT Employees.EmployeeID, Count(Orders.EmployeeID) AS CountOfOrders
FROM Employees, Orders
WHERE (((Employees.EmployeeID)=[Orders].[EmployeeID]))
GROUP BY Employees.EmployeeID;



However, I am uncertain how to proceed from here and find the >AVG part of this query. I know it would be something like this:

SELECT qrycountOfOrders.EmployeeID, Employees.FirstName, Employees.LastName, qrycountOfOrders.CountOfOrders,
FROM qrycountOfOrders, Employees
WHERE qrycountOfOrders.EmployeeID = Employees.EmployeeID;


Any help would be appreciated- thankyou!
Oct 17 '06 #4
Thanks a lot I will try it as a form =)
Oct 17 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Zapp | last post by:
Hi Can anyone tell me why my form script fails at this line <form action="$_SERVER" method="POST"> when running on my ISP which is using PHP version 4.3.2, Configure Command './configure'...
56
by: john bailo | last post by:
I just installed mono from ximian on my redHat 9 workstation and wrote a simple program from the interesting book ado.net in c# by Mahesh Chand. mono is fun ( is there ado for linux ? ...
29
by: Jim Hubbard | last post by:
Yet another hotfix alert (http://www.kbalertz.com/Feedback_823535.aspx) that states "To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix." ...
1
by: zeny | last post by:
Hey you all, i´ve been confrontated with a bizarre thing: i´m doing a binary tree in C and in the file Tree.h i did this: //headers & other stuff typedef struct Node Node_t; struct Node{ ...
2
by: stromhau | last post by:
When compiling i get these warnings and i dont know why. Can anyone please explain ? Tommy, 1>------ Build started: Project: sdl, Configuration: Release Win32 ------ 1>Compiling......
1
by: aling | last post by:
Damn! SQLServer2000 can't add a NOT NULL COLUMN even in one empty existing table! That is, A is the existing table and it is emtpy, I want to add one NOT NULL COLUMN (col_new) to A using following...
4
by: Vaurdan | last post by:
Hello, I've this code: def print_tabela(tabela): print "Tabela 1 | Tabela 2" for linha in tabela: tmp = linha.split(":") print tmp + " | " + tmp, But give me this error: Tabela 1 | Tabela 2
1
by: Ian11 | last post by:
I am new to Linux and Xammp and have downloaded everthing and the server is running. I hve set up a firewall and given permisions to "permit= "80 21"" and I can access the server via localhost on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.