选择每天员工缺勤的计数
好吧,假设我有三个表,如下所示:
员工(ID,姓名)
会话(ID、starts_at、ends_at、day)
缺勤(ID、employeeID、sessionID)
可以说每天有多个会话。
是否可以选择计算会话表上每个不同日期的会话中员工的缺勤情况并将其分组如下:(
--------------------------------
| Name |2011-01-15| 2011-01-16 |
| | | |
|john | 2 | 0 |
|dave | 4 | 1 |
列数(天数)取决于会话表上的天数,假设我只想要那些上周或本周
谢谢。
alright, so lets say i have three tables, as follows :
employees(ID, name)
sessions(ID, starts_at, ends_at, day)
absences(ID, employeeID, sessionID)
lets say there are multiple sessions per day.
is it possible to select count the Absences of employees from sessions for each distinct day on the sessions table and group them as follows :
--------------------------------
| Name |2011-01-15| 2011-01-16 |
| | | |
|john | 2 | 0 |
|dave | 4 | 1 |
(number of columns (days) depends on number of days on the sessions table, lets say i only want those of last or current week
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用
PIVOT
语句。就这样:You should use the
PIVOT
statement. There it goes:查找数据透视表。在某些 RDBMS 上,这是内置的。
Look up pivot table. On some RDBMS, this is built in.
我认为你正在谈论 MySQL 并且你想做一个数据透视表。访问 ArtfulSoftware 的 MySQL 站点并查看数据透视表教程:
http://www.artfulsoftware.com/infotree/queries.php
I'm thinking you are talking MySQL and you want to do a pivot table. Go to ArtfulSoftware's MySQL site and review the pivot table tutorials:
http://www.artfulsoftware.com/infotree/queries.php