1

我想在mysql中做一个考勤系统。比如说两个不同的日期。2017-12-21 和 2017-12-23

如果我有

我的表测试看起来像这样。姓名 日期 出席评论

Person 1 2017-12-21 Yes comment
Person 1 2017-12-23 Yes comment
Person 2 2017-12-21 No  comment 
Person 2 2017-12-23 Yes comment

我想要的结果是

-----2017-12-21----------------2017-12-23-----------
-----Person 1 Yes comment ---- Person 1 Yes comment
-----Person 2 NO  comment ---- Person 2 Yes comment
----------------------------------------------------

认为 leftjoin 会起作用,但对我来说很难有人可以帮忙吗?谢谢。

4

2 回答 2

0

我不太确定您期望的确切格式。如果您的表结构如下所示,

CREATE TABLE IF NOT EXISTS `attendance` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `date` date NOT NULL,
  `attendance` varchar(10) NOT NULL,
  `comment` varchar(1023) NOT NULL,
  PRIMARY KEY (`id`)
);

您可以运行以下查询,

SELECT date, 
GROUP_CONCAT(`name`, ' ', `attendance`, ' ', `comment`) AS attendance_info 
FROM `attendance`
GROUP BY `date`

以以下格式提取数据。

date        | attendance_info

2017-12-21  | Person 1 YES Comment,Person 2 NO Comment

2017-12-23  | Person 1 YES Comment,Person 1 YES Comment
于 2017-11-20T15:34:19.080 回答
0

它为一个运动队。我有这个我的数据库现在我已经测试了很多方法来做到这一点。Group_Contact 不起作用。

CREATE TABLE IF NOT EXISTS `attendance` (
      `playerid` int(11) NOT NULL,
      `idnumber` int(11) NOT NULL AUTO_INCREMENT,
      `name` varchar(255) NOT NULL,
      `date` date NOT NULL,
      `attendance` varchar(10) NOT NULL,
      `comment` varchar(1023) NOT NULL,
      PRIMARY KEY (`playerid`)
);

这是我以后想在 php 中使用它的结果。(a = 出席 c = 评论)

attendance| Name     | a2017-12-21|c2017-12-21|a2017-12-23|c2017-12-23|

          | Person 1 |     YES    |   Comment |     NO    |  Comment  |

          | Person 2 |     YES    |   Comment |    YES    |  Comment  |
于 2017-11-21T21:00:19.907 回答