如何解决在MySQL中将行动态转置为列
我想连续30天显示员工的每月出勤情况。它应该包含按日计的“ Time In”和“ Time Out”。
请帮助我解决这个问题。
我的表包含以下数据
Insert into staff values (1,'Srinivas','Training');
Insert into staff values (2,'Govada','Training');
Create table Bio
(
Bio_id int Not Null AUTO_INCREMENT,Staff_id Int Not Null,DateIn Datetime,DateOut Datetime,CONSTRAINT Bio_pk PRIMARY KEY (Bio_id)
);
--First Employee
Insert into Bio values (1,1,'2020-08-01 09:00:00','2020-08-01 16:00:00');
Insert into Bio values (2,'2020-08-02 09:00:00','2020-08-02 16:00:00');
Insert into Bio values (3,'2020-08-03 09:00:00','2020-08-03 16:00:00');
Insert into Bio values (4,'2020-08-04 09:00:00','2020-08-04 16:00:00');
Insert into Bio values (5,'2020-08-05 09:00:00','2020-08-05 16:00:00');
Insert into Bio values (6,'2020-08-06 09:00:00','2020-08-06 16:00:00');
Insert into Bio values (7,'2020-08-07 09:00:00','2020-08-07 16:00:00');
Insert into Bio values (8,'2020-08-08 09:00:00','2020-08-08 16:00:00');
Insert into Bio values (9,'2020-08-09 09:00:00','2020-08-09 16:00:00');
Insert into Bio values (10,'2020-08-10 09:00:00','2020-08-10 16:00:00');
-第二雇员
Insert into Bio values (11,2,'2020-08-01 16:00:00');
Insert into Bio values (12,'2020-08-02 16:00:00');
Insert into Bio values (13,'2020-08-03 16:00:00');
Insert into Bio values (14,'2020-08-04 16:00:00');
Insert into Bio values (15,'2020-08-05 16:00:00');
Insert into Bio values (16,'2020-08-06 16:00:00');
Insert into Bio values (17,'2020-08-07 16:00:00');
Insert into Bio values (18,'2020-08-08 16:00:00');
Insert into Bio values (19,'2020-08-09 16:00:00');
Insert into Bio values (20,'2020-08-10 16:00:00');
使用查询表中的数据
SELECT Staff_id as id,date_format(Datein,'%Y-%m-%d') as date,'%H-%i') as TimeIn,date_format(DateOut,'%H-%i') as TimeOut
FROM Bio
group
by Staff_id,date(Datein);
Staff_id AttDate TimeIn Time Out
1 2020-08-01 09-00 16-00
1 2020-08-02 09-00 16-00
1 2020-08-03 09-00 16-00
1 2020-08-04 09-00 16-00
1 2020-08-05 09-00 16-00
1 2020-08-06 09-00 16-00
1 2020-08-07 09-00 16-00
1 2020-08-08 09-00 16-00
1 2020-08-09 09-00 16-00
1 2020-08-10 09-00 16-00
2 2020-08-01 09-00 16-00
2 2020-08-02 09-00 16-00
2 2020-08-03 09-00 16-00
2 2020-08-04 09-00 16-00
2 2020-08-05 09-00 16-00
2 2020-08-06 09-00 16-00
2 2020-08-07 09-00 16-00
2 2020-08-08 09-00 16-00
2 2020-08-09 09-00 16-00
2 2020-08-10 09-00 16-00
所需输出:要在整个月的每一行中每天显示每个员工的进出时间。
----------
Staff_id 2020-08-01 2020-08-02 2020-08-03
----------
1 09:00 16:00 09:00 16:00 09:00 16:00
请帮助我在MySQL中编写查询
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。