使用sql查询来显示T_temperature和T_Badende_per_Time及其值。我的sql查询使用Cast将值的逗号改为点,这不是问题所在。问题是,我的sql查询选择了对立面标题的值,如您所见:SQL语言:SELECT routines.date, routines.time,SUM( IF( measurements.title = 'T_Temperatur', CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ), 0 ) ) AS T_Temperatur,SUM( IF( measurements.title = 'T_Badende_per_Time', CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ), 0 ) ) AS Badende,SUM( IF( measurements.title = 'T_Luft_temperatur', CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ), 0 ) ) AS Luft_TempFROM routinesINNER JOIN measure_routine ON routines.id = measure_routine.routine_idINNER JOIN measurements ON measure_routine.measure_id = measurements.idGROUP BY routines.date, routines.timeORDER BY routines.date, routines.time;我的数据库是用日常工作:测量程序:测量: 最佳答案 交换IF()函数中的参数,如果条件为真,则返回0!如果(expr1、expr2、expr3)如果expr1为真(expr10和expr1NULL),则If()返回expr2;否则返回expr3。SELECT routines.date, routines.time, SUM(IF(measurements.title='T_Temperatur', CAST(REPLACE(routines.value,',','.' ) AS DECIMAL(18,2)), 0)) AS T_Temperatur, SUM(IF(measurements.title='T_Badende_per_Time', CAST(REPLACE(routines.value,',','.') AS DECIMAL(18,2)), 0)) AS BadendeFROM routinesINNER JOIN measure_routine ON routines.id = measure_routine.routine_idINNER JOIN measurements ON measure_routine.measure_id = measurements.idorder by routines.date, routines.time关于mysql - SQl查询显示相反的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22805043/ 10-11 03:00