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 8340227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:07:19+00:00 2026-06-09T05:07:19+00:00

I have an attendance table that I’m trying to query in order to create

  • 0

I have an attendance table that I’m trying to query in order to create a dataset that I can graph with. My table stores attendance information like so:

date       | student_id | present | session |
-----------|------------|---------|---------|
2012-09-01 | 1          | 1       | AM      |
2012-09-01 | 1          | 1       | PM      |
2012-09-01 | 2          | 0       | AM      |
2012-09-01 | 2          | 1       | PM      |
2012-09-02 | 1          | 0       | AM      |
2012-09-02 | 1          | 0       | PM      |
2012-09-02 | 2          | 0       | AM      |
2012-09-02 | 2          | 0       | PM      |

I’m trying to end up with a dataset that has each unique date, along with the number of present marks (divided by two, eventually, for a kinda accurate representation of attendance for each day).

2012-09-01 | 3 (1.5)
2012-09-02 | 0 (0)

This is so far the closest I’ve got

AttendanceMark.group(:date).count(:conditions => "present = 1")

but this resulting hash doesn’t include the dates where there are no present marks at all. How would I go about achieving this?

  • 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-06-09T05:07:21+00:00Added an answer on June 9, 2026 at 5:07 am

    If you are using 0 and 1 for present and absent respectively, you can construct a query like this

    # For MySQL
    AttendanceMark.group(:date).sum('CASE present WHEN TRUE THEN 1 ELSE 0 END')
    
    # For SQLite
    AttendanceMark.group(:date).sum('CASE WHEN present = "t" THEN 1 ELSE 0 END')
    

    This shall return

    { "2012-09-01" => 3, "2012-09-02" => 0 }
    

    You can later divide all the sums by two.

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

Sidebar

Related Questions

I'm trying to create an app that will help keep track of attendance information
So I have a SQL table that contains time-clock information like this. The number
I have a table that tracks attendance in a course. The columns are the
I have a table that looks like this: studentID | subjectID | attendanceStatus |
I have employees attendance table from date 1 to 31 with column names like
I have an attendance table that displays how I want it to display but
I have table named Attendance which looks like this: Sno SecurityGroup SecurityName Designation AttendanceStatus
I have a table full of attendance data for students, we are migrating to
I have a nested resource that looks like this: resources :events resources :attendances post
I have the following tables: CREATE TABLE `attendance_event_attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT,

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.