CREATE VIEW memorin.devices_summary AS SELECT total_devices, active_devices, total_devices - active_devices AS inactive_devices FROM ( SELECT COUNT(*) AS total_devices FROM memorin.devices ) AS d, ( SELECT COUNT(*) AS active_devices FROM memorin.devices WHERE deactivated_at IS NULL ) AS a;