Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 687647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:08:55+00:00 2026-05-14T02:08:55+00:00

Okay, I need help. I’m usually pretty good at SQL queries but this one

  • 0

Okay, I need help. I’m usually pretty good at SQL queries but this one baffles me. By the way, this is not a homework assignment, it’s a real situation in an Access database and I’ve written the requirements below myself.


Here is my table layout. It’s in Access 2007 if that matters; I’m writing the query using SQL.

Id (primary key)
PersonID (foreign key)
EventDate
NumberOfCredits
SuperCredits (boolean)

There are events that people go to. They can earn normal credits, or super credits, or both at one event. The SuperCredits column is true if the row represents a number of super credits earned at the event, or false if it represents normal credits.

So for example, if there is an event which person 174 attends, and they earn 3 normal credits and 1 super credit at the event, the following two rows would be added to the table:

ID PersonID EventDate NumberOfCredits SuperCredits
1  174      1/1/2010  3               false
2  174      1/1/2010  1               true

It is also possible that the person could have done two separate things at the event, so there might be more than two columns for one event, and it might look like this:

ID PersonID EventDate NumberOfCredits SuperCredits
1  174      1/1/2010  1               false
2  174      1/1/2010  2               false
3  174      1/1/2010  1               true

Now we want to print out a report. Here will be the columns of the report:

PersonID
LastEventDate
NumberOfNormalCredits
NumberOfSuperCredits

The report will have one row per person. The row will show the latest event that the person attended, and the normal and super credits that the person earned at that event.

What I am asking of you is to write, or help me write, the SQL query to SELECT the data and GROUP BY and SUM() and whatnot. Or, let me know if this is for some reason not possible, and how to organize my data to make it possible.


This is extremely confusing and I understand if you do not take the time to puzzle through it. I’ve tried to simplify it as much as possible, but definitely ask any questions if you give it a shot and need clarification. I’ll be trying to figure it out but I’m having a real hard time with it, this is grouping beyond my experience…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:08:55+00:00Added an answer on May 14, 2026 at 2:08 am

    Create a query/view of the following (say its called PersonLastEvents):

    select PersonId, max(EventDate) as LastEventDate
    from Events
    group by PersonId
    

    Then you can get the data you need with the following. I’m not fully familiar with Access, so you may need to modify some of the syntax, but hopefully this will give you an approach.

    select l.PersonId, l.LastEventDate, 
      sum(case when e.SuperCredits = 'false' then e.NumberOfCredits end) 
        as NumberOfNormalCredits
      sum(case when e.SuperCredits = 'true' then e.NumberOfCredits end) 
        as NumberOfSuperCredits
    from PersonLastEvents l
    join Events e on l.PersonId = e.PersonId and l.LastEventDate = l.EventDate
    group by l.PersonId, l.LastEventDate
    

    As an aside, it may be easier to change your table to have two number columns (NormalCredits, SuperCredits) as it allows you to simply sum() the columns as required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Okay so im working on this php image upload system but for some reason
Okay, I've looked all over the internet for a good solution to get PHP
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
Okay. I know this looks like the typical Why didn't he just Google it
Okay, so I'm running a small test webserver on my private network. I've got
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay, so I'm making a table right now for Box Items. Now, a Box
Okay, we know that the following two lines are equivalent - (0 == i)
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.