If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Calculated Queries?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-06-11, 17:24
uperkurk uperkurk is offline
Registered User
 
Join Date: Nov 2011
Posts: 8
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:

SELECT edi_username, edi_blog_title.......

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.
Reply With Quote
  #2 (permalink)  
Old 12-06-11, 20:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
subquery is not needed

COUNT and GROUP BY are needed
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-07-11, 06:39
uperkurk uperkurk is offline
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.
Reply With Quote
  #4 (permalink)  
Old 12-07-11, 06:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 12-07-11, 07:17
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Quote:
Originally Posted by uperkurk View Post
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
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton

Last edited by healdem; 12-07-11 at 07:22.
Reply With Quote
  #6 (permalink)  
Old 12-07-11, 09:08
uperkurk uperkurk is offline
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.....
Reply With Quote
  #7 (permalink)  
Old 12-07-11, 09:41
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Quote:
Originally Posted by uperkurk View Post
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.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On