SELECT T1.regelnummer AS regelnummer, T1.timestamp AS timestamp, T1.OmvormerIndex AS OmvormerIndex, T1.Vandaag_Verbruik_kWh AS Vandaag_Verbruik_kWh, T1.Vandaag_EnergFromNet_kWh AS Vandaag_EnergFromNet_kWh, T1.Vandaag_EnergyFromInstallatie_kWh AS Vandaag_EnergyFromInstallatie_kWh, T1.Verbruik_kWh AS Verbruik_kWh, T1.EnergFromNet_kWh AS EnergFromNet_kWh, T1.EnergyFromInstallatie_kWh AS EnergyFromInstallatie_kWh, T1.Verbruik_kWh - ( SELECT T2.Verbruik_kWh FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik T2 WHERE T2.OmvormerIndex = T1.OmvormerIndex AND T2.timestamp < T1.timestamp ORDER BY T2.timestamp DESC LIMIT 1 ) AS Used_Today, T1.EnergyFromInstallatie_kWh - ( SELECT T2.EnergyFromInstallatie_kWh FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik T2 WHERE T2.OmvormerIndex = T1.OmvormerIndex AND T2.timestamp < T1.timestamp ORDER BY T2.timestamp DESC LIMIT 1 ) AS FromSolar_Today, T1.EnergFromNet_kWh - ( SELECT T2.EnergFromNet_kWh FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik T2 WHERE T2.OmvormerIndex = T1.OmvormerIndex AND T2.timestamp < T1.timestamp ORDER BY T2.timestamp DESC LIMIT 1 ) AS FromNet_Today FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik T1 WHERE ( SELECT COUNT(0) FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik T2 WHERE T2.OmvormerIndex = T1.OmvormerIndex AND T2.timestamp < T1.timestamp ) > 0 ORDER BY T1.timestamp DESC, T1.OmvormerIndex; Version 2 of the Query SELECT T1.OmvormerIndex AS OmvormerIndex, DATE(T1.timestamp) AS date, MAX(T1.timestamp) AS timestamp, SUM(T1.Verbruik_kWh) AS Verbruik_kWh, SUM(T1.EnergyFromInstallatie_kWh) AS EnergyFromInstallatie_kWh, SUM(T1.EnergFromNet_kWh) AS EnergFromNet_kWh FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik T1 INNER JOIN ( SELECT OmvormerIndex, DATE(timestamp) AS date, MAX(timestamp) AS timestamp FROM ptrp594989_voodevve.ZEIST_2e_Hogeweg_2__Verbruik WHERE Verbruik_kWh IS NOT NULL GROUP BY OmvormerIndex, DATE(timestamp) ) T2 ON T1.OmvormerIndex = T2.OmvormerIndex AND DATE(T1.timestamp) = T2.date AND T1.timestamp = T2.timestamp GROUP BY T1.OmvormerIndex, DATE(T1.timestamp) ORDER BY T1.timestamp DESC, T1.OmvormerIndex