-
Notifications
You must be signed in to change notification settings - Fork 22
Add : Lab wide attendance aggregate data #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
| r#" | ||
| SELECT | ||
| all_dates.date, | ||
| p.present_count | ||
| FROM ( | ||
| SELECT | ||
| date, | ||
| COUNT(*) AS total_count | ||
| FROM attendance | ||
| WHERE date BETWEEN "#, | ||
| ); | ||
|
|
||
| query.push_bind(start_date); | ||
| query.push(" AND "); | ||
| query.push_bind(end_date); | ||
| query.push(" GROUP BY date ) AS all_dates "); | ||
|
|
||
| // sub query of present members joined with the above total countS | ||
| query.push( | ||
| "LEFT JOIN ( | ||
| SELECT | ||
| date, | ||
| COUNT(*) AS present_count | ||
| FROM attendance | ||
| WHERE is_present = 't' | ||
| AND date BETWEEN ", | ||
| ); | ||
| query.push_bind(start_date); | ||
| query.push(" AND "); | ||
| query.push_bind(end_date); | ||
| query.push( | ||
| " GROUP BY date | ||
| ) AS p | ||
| ON all_dates.date = p.date | ||
| ORDER BY all_dates.date;", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the $1, $2 with .bind() syntax to format your SQL. Refer to the other queries in member_queries for examples. The way its formatted right now with multiple push and push_bind's makes it very hard to read.
Will review the SQL logic after its formatted properly.
| FROM ( | ||
| SELECT | ||
| date, | ||
| COUNT(*) AS total_count | ||
| FROM attendance | ||
| WHERE date BETWEEN $1 AND $2 | ||
| GROUP BY date | ||
| ) AS all_dates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query is for the attendance summary widget on the Home dashboard which does not need total_count, moreover, total_count isn't even used in the rest of the query. I'm not sure why you need a join here.
Created a query to get total number of present students in the lab.