我有以下的Mysql查询,它与Sum部分完美配合。我得到的结果是Sum_IO和Sum_NIO正在整个表上计算,就好像标准部分
Cast(oee_main_interim.TS As date) = CurDate()
被忽略了。我想要的是查询只会将今天日期(curdate())下的值相加:
Select
oee_main_interim.NAME As Machine_ID,
oee_machinenames.Name As Name,
voee_mach_shifts.curr_Shift As curr_Shift,
Sum((oee_main_interim.Left_IO + oee_main_interim.Right_IO)) As Sum_IO,
Sum((oee_main_interim.Left_NIO + oee_main_interim.Right_NIO)) As Sum_NIO
From
(oee_main_interim Join
voee_mach_shifts On voee_mach_shifts.ID = oee_main_interim.NAME) Join
oee_machinenames On oee_machinenames.ID = oee_main_interim.NAME
Where
Cast(oee_main_interim.TS As date) = CurDate() And
oee_main_interim.Shift In (Select
voee_mach_shifts.curr_Shift
From
voee_mach_shifts Join
oee_machinenames On oee_machinenames.ID = voee_mach_shifts.ID
Group By
voee_mach_shifts.curr_Shift, oee_machinenames.ID
Order By
oee_machinenames.ID)
Group By
oee_main_interim.NAME, oee_machinenames.Name, voee_mach_shifts.curr_Shift
Order By
oee_system.oee_main_interim.NAME
答案 0 :(得分:0)
您可以使用DATE(yourfield)=CURDATE()
仅匹配时间戳或日期时间字段的日期部分。