# Thread: Calculated Queries?

1. Registered User
Join Date
Nov 2011
Posts
8

## Unanswered: Calculated Queries?

Hey guys, I have to make a calculated query which reads

Query 2 (6%)

For each Editor, calculate and retrieve their Username, Blog Title, and a count of how many Posts they have made.

So far I have this:

I think I have to use a sub query and a COUNT keyword but I just cant figure it out for the life of me..

The tables I have are Editor, Posts and Comments

Editor makes a post, each post can have many comments.

2. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002
subquery is not needed

COUNT and GROUP BY are needed

3. Registered User
Join Date
Nov 2011
Posts
8
Could you be just a little more specific? I have no idea what the code is for the query.

4. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002
no idea?

if at this point in the course you do not understand what COUNT and GROUP BY mean, then i am afraid i cannot help you

homework is assigned for a reason

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
Originally Posted by uperkurk
Could you be just a little more specific? I have no idea what the code is for the query.
certainly
Select
manual: MySQL :: MySQL 5.0 Reference Manual :: 12.2.8 SELECT Syntax
examples: Select - Google Search

Group By
manual: MySQL :: MySQL 5.0 Reference Manual :: 11.15.1 GROUP BY (Aggregate) Functions
example: mysql group by - Google Search

Count
manual: MySQL :: MySQL 5.1 Reference Manual :: 3.3.4.8 Counting Rows
examples: mysql count - google search
Last edited by healdem; 12-07-11 at 07:22.

6. Registered User
Join Date
Nov 2011
Posts
8
Thanks ill have a read through those

And before you judge people by saying if by now in the course... I have been learning about queires for just one week and we have never had to do a calculated query before.

All the pervious ones where just like

SELECT emp_bdate, emp_address FROM employee WHERE emp_fName = 'John' AND emp_lName = 'Smith';

As you can see this is incredibly easy and makes perfect sense.... calculated queires are much harder.....

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
Originally Posted by uperkurk
Thanks ill have a read through those

And before you judge people by saying if by now in the course... I have been learning about queires for just one week and we have never had to do a calculated query before.

All the pervious ones where just like

SELECT emp_bdate, emp_address FROM employee WHERE emp_fName = 'John' AND emp_lName = 'Smith';

As you can see this is incredibly easy and makes perfect sense.... calculated queires are much harder.....
not really
its another term or two in the select clause
the only complication is how the data is aggregated and sorted (read grouped) and the correct way of limiting the data in place of where use a having clause

the SQL engine does the hard work for you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•