SELECT
	SUM(CASE WHEN (kiosk_config.kiosk = 0 OR kiosk_config.kiosk IS NULL) THEN 1 ELSE 0 END) AS attendanceDevices,
    SUM(kiosk_config.kiosk) AS kioskDevices,
    COUNT(d.device_id) AS totalDevices
FROM
    device d
        LEFT JOIN
    (
        SELECT
            d.device_id ,
		CASE
			WHEN (ds.device_setting_value IS NULL
			OR ds.device_setting_value = '') THEN 0
			ELSE 1 END AS kiosk
        FROM
            device d
                LEFT JOIN devicesetting ds ON
                    d.device_id = ds.assigned_device_id
        WHERE
                d.customer_id = :customerparam
          AND d.application = 'VISITOR_CONTROL'
          AND device_setting_key = 'KIOSK_MODE_URL') AS kiosk_config
    ON
            d.device_id = kiosk_config.device_id
WHERE
        d.customer_id = :customerparam
  AND d.application = 'VISITOR_CONTROL'