G
Guest
I've been having a problem with grouping in my queries and
I finally figured out how to do what John Spencer
suggested ...
SELECT [Dept],
Sum(IIF([Major]<30,CyTotal,0)) as Under30,
Sum(IIF([Major]>=30,CyTotal,0)) as Over30
FROM YourTable
GROUP BY [Dept]
An alternative, would be to build a category using an IIF
statement and Group by that
SELECT [Dept],
IIF(Major<30,"Under30","Over30") as Category,
SUM(CyTotal) as Total
FROM YourTable
GROUP BY [Dept],
IIF(Major<30,"Under30","Over30")
However, when I do this (either one) I get the following
message:
"You have written a subquery that can return more than one
field without using the EXISTS reserve word in the main's
query's FROM clause. Revise the SELECT statement of the
subquery to request only one field."
What in the world ?????
This is an explanation of my actual problem ...
SELECT [Dept],
Sum(IIF([Major]<30,CyTotal,0)) as Under30,
Sum(IIF([Major]>=30,CyTotal,0)) as Over30
FROM YourTable
GROUP BY [Dept]
An alternative, would be to build a category using an IIF
statement and Group by that
SELECT [Dept],
IIF(Major<30,"Under30","Over30") as Category,
SUM(CyTotal) as Total
FROM YourTable
GROUP BY [Dept],
IIF(Major<30,"Under30","Over30")
I finally figured out how to do what John Spencer
suggested ...
SELECT [Dept],
Sum(IIF([Major]<30,CyTotal,0)) as Under30,
Sum(IIF([Major]>=30,CyTotal,0)) as Over30
FROM YourTable
GROUP BY [Dept]
An alternative, would be to build a category using an IIF
statement and Group by that
SELECT [Dept],
IIF(Major<30,"Under30","Over30") as Category,
SUM(CyTotal) as Total
FROM YourTable
GROUP BY [Dept],
IIF(Major<30,"Under30","Over30")
However, when I do this (either one) I get the following
message:
"You have written a subquery that can return more than one
field without using the EXISTS reserve word in the main's
query's FROM clause. Revise the SELECT statement of the
subquery to request only one field."
What in the world ?????
This is an explanation of my actual problem ...
would look something like:I'm having trouble with "Group By" Queries.
I need to write a report that lists major > 30 and then
major < 30. So if I had the following information
dept Major CYTotal
10 15 100
10 30 125
15 25 100
15 30 100
15 31 450
In my report I would have
Dept Major > 30 Major < 30
10 100 125
15 100 550 (major 30 & 31 added together)
I know I need to do a group by and group all majors above
30 and all majors below 30 together, however, I 'm
confused as to how to separate them. Here's the code I
have so far. Any help would be greately appreciatedThat
SELECT [Dept],
Sum(IIF([Major]<30,CyTotal,0)) as Under30,
Sum(IIF([Major]>=30,CyTotal,0)) as Over30
FROM YourTable
GROUP BY [Dept]
An alternative, would be to build a category using an IIF
statement and Group by that
SELECT [Dept],
IIF(Major<30,"Under30","Over30") as Category,
SUM(CyTotal) as Total
FROM YourTable
GROUP BY [Dept],
IIF(Major<30,"Under30","Over30")