Results 1 to 2 of 2
  1. #1
    anemoskkk is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2011
    Posts
    12

    Question Group by query

    SELECT Job.City, (COUNT(*) AS "JobsCount", (COUNT(NULLIF( TowedInformation.JobID<>Job.JobID, 1))) AS "FIXED"
    FROM Job TowedInformation
    GROUP BY Job.City


    I was hoping this would have displayed

    City JobCount Fixed
    London 6 3
    Liverpool 7 1

    A syntax error comes up

    Can someone tell me where I went wrong?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Where did you find "NULLIF"?? I have Acc2003 so it may be valid in a newer version??
    You are working with 2 tables Job and TowedInformation, so you need to identify them as 2 tables in your FROM.
    You need some field to "join" the tables. What field is common to both Job and TowedInformation?
    Your first COUNT does not have a closing )
    FIXED is a reserved word so avoid it.
    Code:
    SELECT Job.City, (COUNT(*) AS "JobsCount" , (COUNT(NULLIF( TowedInformation.JobID<>Job.JobID, 1))) AS  "FIXED" 
    FROM Job TowedInformation
    GROUP BY Job.City
    I'm not sure what fields and keys are really in your Tables, but the syntax will be something along these lines. I'm not sure how you were determining "FIXED" so you'd have to adjust for that.
    Code:
    SELECT Job.City
     , COUNT(*) AS JobsCount
    XXXX  "FIXED " Stuff here XXXX
    FROM 
    Job 
    ,TowedInformation
    WHERE
    Job.JobId = TowedInformation.JobId
    GROUP BY Job.City
    Hope it helps.

    Have you tried Google to find any samples or examples?
    For SQL stuff you can look to http://www.w3schools.com/sql/default.asp
    Last edited by orange; 04-16-2011 at 07:01 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Group query results
    By shak2 in forum Access
    Replies: 7
    Last Post: 10-20-2010, 02:41 PM
  2. SQL query with SUM, INNER JOIN and GROUP BY
    By BayerMeister in forum Queries
    Replies: 2
    Last Post: 08-14-2010, 12:55 AM
  3. Group by Week in a Crosstab Query
    By NMJones in forum Access
    Replies: 1
    Last Post: 06-24-2010, 04:09 PM
  4. query group by
    By fanfan2 in forum Queries
    Replies: 3
    Last Post: 03-12-2010, 03:07 PM
  5. columns for group detail but not group header?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums