1
這是結果我的腳本任何人都可以幫助按此日期分組。就像你在圖片上看到的那樣,它在每個計數器中給出4行。 This is the image of output如何將複製數據值分組到我的腳本
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'
請注意DISTINCT不是函數。並參見https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-查詢 – Strawberry
你能提供一個輸出應該是什麼樣子的文本示例嗎?這通常有助於 – stombeur
@stombeur用戶的日誌應該在組中。 –