Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 22, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/a1b7f2db2cb1c8d3742e9159073ebbbc to your computer and use it in GitHub Desktop.
Save codecademydev/a1b7f2db2cb1c8d3742e9159073ebbbc to your computer and use it in GitHub Desktop.
Codecademy export
DELETE FROM panels
WHERE ID = 'ID';
UPDATE patients
SET Status = "active"
WHERE ID = 7;
CREATE TABLE inactive_patients
AS SELECT *
FROM patients
WHERE Status = "inactive";
DELETE FROM patients
WHERE status = "inactive";
ALTER TABLE patients
RENAME TO active_patients;
WITH total_active AS (
SELECT COUNT(ID) AS 'active'
FROM active_patients
),
total_inactive AS (
SELECT COUNT(ID) AS 'inactive'
FROM inactive_patients
),
total_patients AS (
SELECT total_active.active + total_inactive.inactive AS 'total'
FROM total_active, total_inactive
)
SELECT
(total_active.active*100 / total_patients.total) AS 'percent_active',
(total_inactive.inactive*100 / total_patients.total) AS 'percent_inactive'
FROM total_active, total_inactive, total_patients;
select *
from active_patients
order by ID desc
limit 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment