Results 1 to 6 of 6

Thread: Query

  1. #1
    Join Date
    Apr 2004
    Posts
    9

    Question Unanswered: Query

    Greetings,

    I have three queries that I have to put together and they are based on the SELECT and GROUP BY.

    1st Query requirement:
    group the Employees by Job Code. Use a SELECT query.and modify the SQL

    My answer is (and I'm not able to see the actual names and job codes):
    SELECT 'EmployeeID' AS EmployeeID, 'FirstName' AS FirstName, 'LastName' AS LastName, 'JobTitleCode' AS JobTitleCode
    FROM Employees_Table
    GROUP BY EmployeeID, FirstName, LastName, JobTitleCode
    ORDER BY JobTitleCode;


    2nd Query requirement:
    group the Employees by Salary. Use a SELECT Query and modify the SQL

    My answer is (and very similar to the above, I'm not seeing the information):
    SELECT 'Employee ID' AS EmployeeID, 'FirstName' AS FirstName, 'LastName' AS LastName, 'Salary' AS Salary
    FROM Employees_Table
    GROUP BY EmployeeID, FirstName, LastName, [Salary]
    ORDER BY [Salary];

    Last Query requirement:
    group the Employees by Salary within their Job Code. Use a SELECT Query and modify the SQL

    My rough draft answer (not really sure at this point :-( is:
    SELECT 'First Name' AS FirstName, 'Last Name' AS LastName, 'Salary' AS Salary
    FROM Employees_Table
    GROUP BY 'Salary', 'Job Title Code';

    Any words of wisdom would be greatly appreciated.

    Thanks for your time!

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Looks like a homework...Are you sure the fieldnames are spelled correctly? I don't think your queries will run...

    1st - ...will give an error on invalid field name
    2nd - ...will do the same
    3rd - ...same difference

    But conceptually ... I don't think you are answering the questions. You need to loose GROUP BY and reverse the order of the fields in ORDER BY clause.
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Apr 2004
    Posts
    9

    Thumbs up Query

    Yes, the field names in my database are spelled the same exact way as I've listed them in the SQL statements?

    Any other words of advice?

    Thanks for your time.

  4. #4
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Quote Originally Posted by sqlhelp
    Yes, the field names in my database are spelled the same exact way as I've listed them in the SQL statements?

    Any other words of advice?

    Thanks for your time.
    So, you're saying that 'EmployeeID' and 'Employee ID' are the same field or 2 different fields?
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  5. #5
    Join Date
    Apr 2004
    Posts
    9

    Question

    You are correct and I've modified to the new statements below:

    Query 1:
    SELECT EmployeeID, FirstName, JobTitleCode
    FROM Employees_Table
    GROUP BY EmployeeID, FirstName, JobTitleCode
    ORDER BY JobTitleCode;

    Query 2:
    SELECT EmployeeID, FirstName, [Salary]
    FROM Employees_Table
    WHERE Salary>45000
    GROUP BY EmployeeID, FirstName, [Salary]
    ORDER BY [Salary];

    I hope I'm going in the correct direction with my answers?

    Thanks for your responses!

  6. #6
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    See my first post (loose GROUP BY, because you're not doing any aggregation)
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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