Querying MIMIC-III in Postgres

Here I assume that the MIMIC-III database is on your default search path. To change this in PostgreSQL, run the following command:

set search_path to mimiciii;

In my environment, MIMIC-III is installed under the schema mimiciii, which may be different on your system.

Obtain metadata for a particular table in Postgres with \d+ <schema>.<tablename>. For example, the following command prints metadata for the patients table.

mimic=# \d+ mimiciii.patients;

Obtain the number of patients with the following query:

mimic=# SELECT COUNT(*) FROM patients;
 count
-------
 46520
(1 row)

Obtain the distinct values used to indicate gender in the “gender” column using the following query:

mimic=# SELECT DISTINCT(gender) FROM patients;
 gender
--------
 M
 F
(2 rows)

Obtain the number of female patients by adding a condition:

mimic=# SELECT COUNT(*)
mimic-# FROM patients
mimic-# WHERE gender = 'F';
 count
-------
 20399
(1 row)

The number of male and female patients can be obtained using the following query:

mimic=# SELECT gender, COUNT(*)
mimic-# FROM patients
mimic-# GROUP BY gender;
 gender | count
--------+-------
 M      | 26121
 F      | 20399
(2 rows)

A flag which records whether or not a patient died in the hospital is stored in the patients table. Count the number of patients who died using the following query:

mimic=# SELECT expire_flag, COUNT(*)
mimic-# FROM patients
mimic-# GROUP BY expire_flag;
 expire_flag | count
-------------+-------
           0 | 30761
           1 | 15759
(2 rows)

References

Comments

Copied title and URL