I have a table with data that looks like this:
create table demo_patient_info (
attend timestamp,
patient_id int,
blood_pressure double
);
I would like to write (preferably ANSI) SQL queries that allow me to do the following:
query1:
return the difference between bp of all patients with each other (using a WHERE clause to restrict the number of rows returned in the cartesian product)
query2:
return the difference between bp of each patient and one specific (i.e. specified) patient in the table
1)
2)
This will likely give two rows for each match though, which may or may not be OK
edit:
WHERE t1.patient_id < t2.patient_idin query 1 is there to prevent the following, duplication and self matchingthanks to Jonathan Leffler for the hint 🙂