I have this query in PHP Laravel:
$sensor_data = DB::table('devices_sensor_data as D')
->select(DB::raw('
D.id,
COALESCE(D.DeviceId,dx.DeviceId) AS DeviceId,
D.ENERGY_Total,
D.Time')
)
->join(DB::raw('
(SELECT
MIN(CONVERT_TZ(Time, "'.$dbTz.'", "'.$usrTz.'")) min_time,
MAX(CONVERT_TZ(Time, "'.$dbTz.'", "'.$usrTz.'")) max_time,
DeviceId
FROM devices_sensor_data
WHERE DATE(Time) BETWEEN "'.$fromTzTime.'" AND "'.$toTzTime.'"
AND DeviceId IN (\''.$arrayDeviceID.'\')
GROUP BY DATE(Time), DeviceId ORDER BY DATE(Time)
) AS dx'
),
function($join)
{
$join->on(DB::raw('D.Time = `dx`.`min_time` OR D.Time'), '=', 'dx.max_time');
$join->where('D.DeviceId', '=', DB::raw('dx.DeviceId'));
})
->whereIn('D.DeviceId', array_keys($devicesArr))
->whereDate('D.Time', '>=', $fromTzTime)
->whereDate('D.Time', '<=', $toTzTime);
$sensor_data = $sensor_data
->orderBy('D.DeviceId')
->orderBy('D.Time')
->get();
I want to select MIN and MAX based on different user based timezone than that is default, right now its Asia/Kolkata, so I want to select it based on eg. America/New_York.
It returns me the MIN and MAX as per IST timezone and just convert that into NewYork timing, but I want to fetch the MIN and MAX according to NewYork TimeZone.
