Mysql 如何将复制数据值分组到我的脚本

Mysql 如何将复制数据值分组到我的脚本,mysql,sql,tsql,Mysql,Sql,Tsql,这是我的脚本的结果,任何人都可以在此日期前帮助分组。如图所示,每个计数器有4行。 MYSQL不允许按特定列区分结果-distinct只能应用于整行,以便返回唯一的行。重复生效日期,因为生效日期、计数器_1、计数器_2、计数器_3和计数器_4的每个新组合都被视为一个不同的行 以上使用group by effectiveDate是否为您提供了所需信息 MYSQL不允许按特定列区分结果-distinct只能应用于整行,以便返回唯一的行。重复生效日期,因为生效日期、计数器_1、计数器_2、计数器_3和

这是我的脚本的结果,任何人都可以在此日期前帮助分组。如图所示,每个计数器有4行。

MYSQL不允许按特定列区分结果-distinct只能应用于整行,以便返回唯一的行。重复生效日期,因为生效日期、计数器_1、计数器_2、计数器_3和计数器_4的每个新组合都被视为一个不同的行

以上使用group by effectiveDate是否为您提供了所需信息

MYSQL不允许按特定列区分结果-distinct只能应用于整行,以便返回唯一的行。重复生效日期,因为生效日期、计数器_1、计数器_2、计数器_3和计数器_4的每个新组合都被视为一个不同的行


上述使用group by effectiveDate是否提供了所需信息?

请注意,DISTINCT不是一个函数。请看,您能否提供一个文本示例,说明输出应该是什么样的?通常helps@stombeur用户的日志应在组中。@stomber示例7:00:00---12:00:00---13:00:00---17:00:00,并且生效日期不应重复。正如您可以看到许多日期的输出。@JobertJayJaducana,您可以从问题中删除标记tsql(特定于Microsoft SQL Server的SQL)吗?在我看来,您提出的问题似乎与查询mysql数据库有关,而不是Microsoft SQL Server。请注意,DISTINCT不是一个函数。请看,您能否提供一个文本示例,说明输出应该是什么样的?通常helps@stombeur用户的日志应在组中。@stomber示例7:00:00---12:00:00---13:00:00---17:00:00,并且生效日期不应重复。正如您可以看到许多日期的输出。@JobertJayJaducana,您可以从问题中删除标记tsql(特定于Microsoft SQL Server的SQL)吗?在我看来,您提出的问题似乎与查询mysql数据库有关,而不是Microsoft SQL Server。
   SELECT DISTINCT(effectiveDate),


      IF(note = "REGULAR LOGGED" and counter = '1',log,
      IF(note = "SICK LEAVE" and counter = '1',"SICK LEAVE",
      IF(note = "VACATION LEAVE" and counter = '1',"VACATION LEAVE",
      IF(note = "HOLIDAY" and counter = '1',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
      IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '1','Saturday',
      IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '1','Sunday','')))))) as COUNTER_1,



      IF(note = "REGULAR LOGGED" and counter = '2',log,
      IF(note = "SICK LEAVE" and counter = '2',"SICK LEAVE",
      IF(note = "VACATION LEAVE" and counter = '2',"VACATION LEAVE",
      IF(note = "HOLIDAY" and counter = '2',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
      IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '2','Saturday',
      IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '2','Sunday','')))))) as COUNTER_2,


       IF(note = "REGULAR LOGGED" and counter = '3',log,
      IF(note = "SICK LEAVE" and counter = '3',"SICK LEAVE",
      IF(note = "VACATION LEAVE" and counter = '3',"VACATION LEAVE",
      IF(note = "HOLIDAY" and counter = '3',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
      IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '3','Saturday',
      IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '3','Sunday','')))))) as COUNTER_3,


        IF(note = "REGULAR LOGGED" and counter = '4',log,
      IF(note = "SICK LEAVE" and counter = '4',"SICK LEAVE",
      IF(note = "VACATION LEAVE" and counter = '4',"VACATION LEAVE",
      IF(note = "HOLIDAY" and counter = '4',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
      IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '4','Saturday',
      IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '4','Sunday','')))))) as COUNTER_4


    FROM schedules sched
      LEFT JOIN timesheet ON sched.empid = timesheet.empid
    WHERE sched.empid='40'
SELECT effectiveDate,


  sec_to_time(SUM(time_to_sec(IF(note = "REGULAR LOGGED" and counter = '1',log,
  IF(note = "SICK LEAVE" and counter = '1',"SICK LEAVE",
  IF(note = "VACATION LEAVE" and counter = '1',"VACATION LEAVE",
  IF(note = "HOLIDAY" and counter = '1',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
  IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '1','Saturday',
  IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '1','Sunday',''))))))))) as COUNTER_1,



  sec_to_time(SUM(time_to_sec(IF(note = "REGULAR LOGGED" and counter = '2',log,
  IF(note = "SICK LEAVE" and counter = '2',"SICK LEAVE",
  IF(note = "VACATION LEAVE" and counter = '2',"VACATION LEAVE",
  IF(note = "HOLIDAY" and counter = '2',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
  IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '2','Saturday',
  IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '2','Sunday',''))))))))) as COUNTER_2,


  sec_to_time(SUM(time_to_sec(IF(note = "REGULAR LOGGED" and counter = '3',log,
  IF(note = "SICK LEAVE" and counter = '3',"SICK LEAVE",
  IF(note = "VACATION LEAVE" and counter = '3',"VACATION LEAVE",
  IF(note = "HOLIDAY" and counter = '3',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
  IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '3','Saturday',
  IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '3','Sunday',''))))))))) as COUNTER_3,


  sec_to_time(SUM(time_to_sec(IF(note = "REGULAR LOGGED" and counter = '4',log,
  IF(note = "SICK LEAVE" and counter = '4',"SICK LEAVE",
  IF(note = "VACATION LEAVE" and counter = '4',"VACATION LEAVE",
  IF(note = "HOLIDAY" and counter = '4',(SELECT description FROM holidays WHERE sched.effectiveDate = holidays.date),
  IF(DAYNAME(sched.effectiveDate)='Saturday' and counter = '4','Saturday',
  IF(DAYNAME(sched.effectiveDate)='Sunday' and counter = '4','Sunday',''))))))))) as COUNTER_4


FROM schedules sched
  LEFT JOIN timesheet ON sched.empid = timesheet.empid
WHERE sched.empid='40'
GROUP BY effectiveDate