Results 1 to 7 of 7
  1. #1
    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:

    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.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    subquery is not needed

    COUNT and GROUP BY are needed
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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
    Last edited by healdem; 12-07-11 at 08:22.
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    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.....

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

Posting Permissions

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