SELECT MAX(Number) AS M3, Workstyle, Process, MAX(Gprocess) AS GP, SUM(Count) AS Total
FROM Work_CountDay2
WHERE CDate BETWEEN '2020-01-08 08:00:01' AND '2020-01-08 20:00:00'
GROUP BY Workstyle, Process ORDER BY M3 DESC
ขอบคุณคับ ถ้าบางทีมันมี max มากกว่า 3 เช่นมันมี 10 แต่อยากจะได้แค่ 3-8 แบบพอทำได้ไหมคับ
Code (SQL)
USE [IE]
GO
select * from (
SELECT MAX(Number) AS M3, Workstyle, Process, MAX(Gprocess) AS GP, SUM(Count) AS Total
FROM Work_CountDay2
WHERE CDate BETWEEN '2020-01-13 08:00:01' AND '2020-01-13 20:00:00'
GROUP BY Workstyle, Process ) as tt WHERE M3 = 3
ORDER BY M3 DESC
GO
ถ้าแบบนี้จะติดค่าที่ไม่ใช่ค่า max สุดมาด้วยคับในกรณีที่มีแค่ 2-3 style Code (SQL)
USE [IE]
GO
select * from (
SELECT MAX(Number) AS M3, Workstyle, Process, MAX(Gprocess) AS GP, SUM(Count) AS Total
FROM Work_CountDay2
WHERE CDate BETWEEN '2020-01-13 08:00:01' AND '2020-01-13 20:00:00'
GROUP BY Workstyle, Process ) as tt
ORDER BY M3 DESC OFFSET 0 ROWS FETCH NEXT 6 ROWS ONLY
GO