SELECT
    SUM(kiosk_config.kiosk = 0 OR kiosk_config.kiosk IS NULL) AS attendanceDevices,
    SUM(kiosk_config.kiosk) AS kioskDevices,
    COUNT(d.device_id) AS totalDevices
FROM
    device d
        LEFT JOIN
    (
        SELECT
            d.device_id ,
            NOT (ds.device_setting_value IS NULL
                OR ds.device_setting_value = '') 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'