Results 1 to 4 of 4
  1. #1
    Lshamz is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    2

    Access SQL queries

    I have some homework with Access that is very difficult, making queries with SQL..



    Here is one question for example:

    List the10 patients with highest annual Medicare bill for year 1996. Result forma by: [PatientID, Year, TotalBilledAmount]

    So I started with
    SELECT TOP 10 SUM(BilledAmount) AS TotalBilledAmount, PatientID , PaymentDate AS
    FROM Claim
    WHERE Year = 1996 ???
    GROUP BY PatientID, TotalBilledAmount, Year
    ORDER BY SUM(BilledAmount)

    I know you cant see the database and column names but they are: BilledAmount, PatientID, PaymentDate, DateOfService, [PaidAmount &DateOfPayment bot from table name called ClaimPayment)...and there isn't a column for year? ...that's where I'm confused...we have two years: 1996 & 1997 listed like dates such as 5/16/1996 and 5/16/1997 for example but does this mean I have to separate the dates by year into 2 new tables or what? I'm so confused.can anyone help make this query for me given the column names?

    thanks so much im so confused


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    The year is probably in [paymentDate] , extract the year with
    year([paymentDate])

  3. #3
    Lshamz is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    2
    So I just write WHERE PaymentDate= 1997 ?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Use the VBA Year() function to get just the year. Try
    Code:
    SELECT TOP 10 SUM(BilledAmount) AS TotalBilledAmount, PatientID , Year(PaymentDate) AS TheYear
    FROM Claim 
    WHERE Year(PaymentDate) = 1996 
    GROUP BY PatientID, TotalBilledAmount, Year(PaymentDate) 
    ORDER BY SUM(BilledAmount)  

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

Similar Threads

  1. New to Access - Help with Queries
    By KFF in forum Queries
    Replies: 1
    Last Post: 08-19-2015, 10:03 AM
  2. Replies: 6
    Last Post: 11-13-2013, 04:17 PM
  3. Need help with Access Web Queries
    By markarmer in forum Queries
    Replies: 0
    Last Post: 02-22-2013, 08:28 AM
  4. Queries in access
    By genobee in forum Queries
    Replies: 1
    Last Post: 11-01-2011, 06:04 AM
  5. Access Pro in Queries need it for project
    By nemolist in forum Programming
    Replies: 2
    Last Post: 10-11-2011, 07:46 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