question_id
int64
0
499
db_id
stringclasses
11 values
question
stringlengths
54
1.57k
evidence
stringlengths
0
418
SQL
stringlengths
41
2.22k
difficulty
stringclasses
3 values
400
thrombosis_prediction
I'm studying patients who carry exactly the rheumatoid arthritis and Sjögren's syndrome overlap. Please look at each patient's own record and find those whose record names exactly rheumatoid arthritis and Sjögren's syndrome, in either order, and no other disease – a disease recorded only as suspected does not count as ...
Rheumatoid arthritis is recorded as the code RA and Sjögren's syndrome as the code SJS. A normal platelet level means a platelet count above 100 and below 400.
SELECT SUM(CASE WHEN EXISTS (SELECT 1 FROM Laboratory AS l WHERE l.ID = p.ID AND l.PLT > 100 AND l.PLT < 400) THEN 1 ELSE 0 END) AS had_normal_platelet_result, SUM(CASE WHEN NOT EXISTS (SELECT 1 FROM Laboratory AS l WHERE l.ID = p.ID AND l.PLT > 100 AND l.PLT < 400) THEN 1 ELSE 0 END) AS never_normal_platelet_result FR...
challenging
401
thrombosis_prediction
I'm writing a report section on abnormal total protein in female SLE patients and need one summary figure. Among the laboratory records of female patients diagnosed with systemic lupus erythematosus at an examination visit, where total protein is above the normal bound of 8.5, what is the average deviation of total pro...
SLE: systemic lupus erythematosus.
SELECT ROUND(AVG(L.TP - 8.5), 3) AS avg_tp_deviation FROM Patient AS P INNER JOIN Laboratory AS L ON L.ID = P.ID WHERE P.SEX = 'F' AND L.TP > 8.5 AND P.ID IN (SELECT ID FROM Examination WHERE Diagnosis LIKE '%SLE%')
challenging
402
thrombosis_prediction
What percentage of patients in the registry with a diagnosis of psoriatic arthritis were born in 1960 or later? Please give a single percentage rounded to one decimal place.
Psoriatic arthritis is a rheumatologic diagnosis recorded for patients in the registry.
SELECT ROUND(CAST(SUM(CASE WHEN STRFTIME('%Y', Birthday) >= '1960' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(*), 1) AS percentage FROM Patient WHERE LOWER(TRIM(Diagnosis)) = 'psoriatic arthritis'
challenging
403
thrombosis_prediction
I'm putting together a demographic summary of our low-albumin patients. Could you tell me how many patients with an albumin measurement below 3.5 are female and how many are male? I'd like one row per sex group showing the sex (F or M) and the number of patients in that group.
F stands for female and M stands for male.
SELECT T1.SEX AS sex, COUNT(DISTINCT T1.ID) AS patient_count FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.ALB < 3.5 AND T1.SEX IN ('F','M') GROUP BY T1.SEX ORDER BY T1.SEX
challenging
404
thrombosis_prediction
I'm preparing a department audit on how often anti-ribonuclear protein testing comes back clearly elevated among the women in the thrombosis cohort. Among the women in the cohort, what percentage of those with an available anti-ribonuclear protein test result had a clearly elevated result? Please give me the percentage...
Anti-ribonuclear protein is a serology test reported as a titer reading; a negative reading is a result of zero titer.
SELECT ROUND(CAST(SUM(CASE WHEN EXISTS (SELECT 1 FROM Laboratory L WHERE L.ID = P.ID AND CAST(L.RNP AS REAL) > 64) THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(*), 2) AS pct FROM Patient P WHERE P.SEX = 'F' AND EXISTS (SELECT 1 FROM Laboratory L WHERE L.ID = P.ID AND L.RNP IS NOT NULL)
challenging
405
thrombosis_prediction
What was the average age of the register's patients in 1999, considering all patients who ever had marked or worse proteinuria on a lab test? Age in 1999 means 1999 minus the patient's year of birth. Marked or worse proteinuria means grade 3 or 4 on the original scale, or 300, 1000 or above on the scale used since 1987...
U-PRO = proteinuria result of a laboratory test; TR = traces of proteinuria.
SELECT AVG('1999' - CAST(STRFTIME('%Y', Birthday) AS INTEGER)) AS average_age FROM Patient WHERE ID IN (SELECT ID FROM Laboratory WHERE `U-PRO` IN ('3','4') OR CAST(REPLACE(`U-PRO`, '>=', '') AS REAL) >= 300)
challenging
406
thrombosis_prediction
I'm looking at patients whose anti-ribonuclear protein antibody measurement came out higher than 32. Of those patients, how many were women and how many were men? Note that 'higher than 32' means strictly above 32, not equal to it, and a patient qualifies if any of their laboratory measurements exceeded 32.
A woman means a patient recorded as F, and a man means a patient recorded as M.
SELECT COUNT(DISTINCT CASE WHEN T1.SEX = 'F' THEN T1.ID END) AS women, COUNT(DISTINCT CASE WHEN T1.SEX = 'M' THEN T1.ID END) AS men FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE CAST(T2.RNP AS REAL) > 32
challenging
407
thrombosis_prediction
I'm studying how early in life a patient in the thrombosis cohort can show a high anti-ribonuclear protein (RNP) reading. Please tell me the youngest age, in whole years, at which a patient had a laboratory test showing an anti-RNP result of at least 64. Age in whole years means the year of the test minus the year of b...
Anti-ribonuclear protein (RNP): an antibody measured in the laboratory panel, reported as a titer number or as negative.
SELECT MIN(STRFTIME('%Y', T2.`Date`) - STRFTIME('%Y', T1.Birthday)) AS youngest_age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE CAST(T2.RNP AS REAL) >= 64
challenging
408
thrombosis_prediction
For the patients in the registry with a diagnosis of psoriatic arthritis, I'd like to know: (1) the total number of laboratory tests recorded for these patients, counting tests from all dates, and (2) how many of these patients have no laboratory tests recorded at all (i.e., patients with no laboratory record count as ...
Psoriatic arthritis: a rheumatic disease diagnosis.
SELECT COUNT(l.ID) AS total_tests, SUM(CASE WHEN l.ID IS NULL THEN 1 ELSE 0 END) AS no_test_patients FROM Patient p LEFT JOIN Laboratory l ON l.ID = p.ID WHERE LOWER(p.Diagnosis) = 'psoriatic arthritis'
challenging
409
thrombosis_prediction
For our annual report, I need the count of patients in the thrombosis cohort who showed thrombosis at any examination performed between 01/01/1997 and 12/31/1997, inclusive. Please give me just that number of patients.
Thrombosis refers to the formation of blood clots, recorded at each examination as a graded finding.
SELECT COUNT(DISTINCT ID) AS patient_count FROM Examination WHERE `Examination Date` BETWEEN '1997-01-01' AND '1997-12-31' AND Thrombosis > 0
challenging
410
thrombosis_prediction
I'm putting together a monitoring checklist for SLE patients. Among the thrombotic episodes recorded for patients diagnosed with SLE, which single symptom appears most frequently? I just need the symptom name back. Please count all recorded episodes with no date restriction. If two symptoms are equally frequent, give t...
SLE: systemic lupus erythematosus, an autoimmune disease. Thrombotic episode: an episode in which the patient experienced thrombosis.
WITH episodes AS (SELECT e.Symptoms FROM Examination e JOIN Patient p ON e.ID = p.ID WHERE Instr(p.Diagnosis, 'SLE') > 0 AND e.Thrombosis > 0) SELECT Symptoms FROM episodes GROUP BY Symptoms HAVING COUNT(*) = (SELECT MAX(n) FROM (SELECT COUNT(*) AS n FROM episodes GROUP BY Symptoms)) ORDER BY Symptoms LIMIT 1
challenging
411
thrombosis_prediction
In our autoimmune disease cohort, what percentage of thrombosis patients were diagnosed with SLE at the examination visit? I need the percentage on a 0-100 scale, rounded to two decimal places. Please use the diagnosis recorded at the examination visit, not the diagnosis on the patient's overall file. This is for a wri...
SLE: systemic lupus erythematosus, an autoimmune disease; thrombosis: formation of a blood clot within a blood vessel
SELECT ROUND(CAST(COUNT(DISTINCT CASE WHEN Diagnosis LIKE '%SLE%' THEN ID END) AS REAL) * 100 / COUNT(DISTINCT ID), 2) AS percentage FROM Examination WHERE Thrombosis > 0
challenging
412
thrombosis_prediction
For the thrombosis cohort, I need to describe how long admitted patients typically wait from their first hospital visit until their first examination. Please give me the average delay in days across admitted patients, based on each patient's own first visit and first examination, rounded to the nearest whole number. A ...
SELECT ROUND(AVG(gap), 0) AS average_days FROM (SELECT T1.ID, MIN(JULIANDAY(T3.`Examination Date`)) - JULIANDAY(T1.`First Date`) AS gap FROM Patient AS T1 INNER JOIN Examination AS T3 ON T1.ID = T3.ID WHERE T1.Admission LIKE '%+%' GROUP BY T1.ID)
challenging
413
thrombosis_prediction
For a demographics summary of our 1994 laboratory cohort: how many female patients and how many male patients had a normal AST glutamic oxaloacetic transaminase (GOT) index on laboratory tests done during the calendar year 1994? Please give me the patient count for each sex (F and M) and nothing else. The calendar year...
AST glutamic oxaloacetic transaminase (GOT) index within normal range means a value below 60.
SELECT p.SEX, COUNT(DISTINCT p.ID) AS patient_count FROM Patient AS p INNER JOIN Laboratory AS l ON p.ID = l.ID WHERE l.GOT < 60 AND l.Date BETWEEN '1994-01-01' AND '1994-12-31' AND p.SEX IN ('F','M') GROUP BY p.SEX
challenging
414
thrombosis_prediction
I'm reviewing thrombosis ward patients and need a chart-review list. Can you give me, for every patient who had a single lab visit where the panel showed both an LDH result strictly between 600 and 800 and urine protein of 300 mg/dL or more, the patient ID and their completed age in years as of 2026-10-09? If any one v...
Proteinuria result codes: '-' means negative, 'TR' means trace.
SELECT p.ID, CAST(SUBSTR('2026-10-09', 1, 4) AS INTEGER) - CAST(SUBSTR(CAST(p.Birthday AS CHAR(10)), 1, 4) AS INTEGER) - CASE WHEN SUBSTR('2026-10-09', 6, 5) < SUBSTR(CAST(p.Birthday AS CHAR(10)), 6, 5) THEN 1 ELSE 0 END AS age FROM Patient AS p WHERE p.Birthday IS NOT NULL AND EXISTS (SELECT 1 FROM Laboratory AS l WHE...
challenging
415
thrombosis_prediction
For the RA patients whose urea nitrogen was within the normal index, how many more women are there than men? Please give me a single integer: the count of women minus the count of men. Women means sex F and men means sex M, and the difference may be negative.
Within the UN normal index means UN < 30; RA means a Diagnosis of RA.
SELECT SUM(CASE WHEN SEX = 'F' THEN 1 ELSE 0 END) - SUM(CASE WHEN SEX = 'M' THEN 1 ELSE 0 END) AS women_minus_men FROM Patient WHERE Diagnosis = 'RA' AND ID IN (SELECT ID FROM Laboratory WHERE UN < 30)
challenging
416
thrombosis_prediction
I'm reviewing renal function in the thrombosis cohort and want to compare how often creatinine runs out of the normal range between men and women. For each sex (M and F), please give me: the number of patients of that sex with at least one creatinine result out of the normal range, the total number of patients of that ...
Creatinine out of the normal range: a CRE value of 1.5 or higher. Male is SEX = 'M'; female is SEX = 'F'.
SELECT P.SEX AS sex, COUNT(DISTINCT CASE WHEN L.CRE >= 1.5 THEN P.ID END) AS out_of_range_patients, COUNT(DISTINCT P.ID) AS total_patients, ROUND(100.0*COUNT(DISTINCT CASE WHEN L.CRE >= 1.5 THEN P.ID END)/COUNT(DISTINCT P.ID),1) AS share_pct FROM Patient AS P LEFT JOIN Laboratory AS L ON P.ID = L.ID WHERE P.SEX IN ('M'...
challenging
417
thrombosis_prediction
In this cohort, I want to compare the most extreme total cholesterol (T-CHO) readings between patients admitted to the hospital and those followed at the outpatient clinic. Please give me, for each of the two groups, the single highest T-CHO reading, along with the admission status ('+' admitted, '-' outpatient) and th...
T-CHO: total cholesterol. '+': the patient was admitted to the hospital. '-': the patient was followed at the outpatient clinic.
SELECT l.`T-CHO` AS `T-CHO`, p.Admission AS status, p.ID FROM Patient p JOIN Laboratory l ON l.ID = p.ID JOIN (SELECT p2.Admission AS adm, MAX(l2.`T-CHO`) AS mx FROM Patient p2 JOIN Laboratory l2 ON l2.ID = p2.ID WHERE p2.Admission IN ('+', '-') GROUP BY p2.Admission) t ON t.adm = p.Admission AND t.mx = l.`T-CHO` ORDER...
challenging
418
thrombosis_prediction
Among patients whose first visit to the hospital was in 1991, which patients mounted the strongest anti-ribonuclear protein (RNP) response? Please give me the patient ID and anti-RNP level for every patient tied at the highest recorded level. Only consider patients for whom a level was actually recorded.
anti-ribonuclear protein (RNP): an antibody titer; a higher titer means a higher level.
SELECT DISTINCT T1.ID, T2.RNP FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE STRFTIME('%Y', T1.`First Date`) = '1991' AND T2.RNP IS NOT NULL AND CAST(T2.RNP AS REAL) = (SELECT MAX(CAST(L.RNP AS REAL)) FROM Patient AS P INNER JOIN Laboratory AS L ON P.ID = L.ID WHERE STRFTIME('%Y', P.`First Date`)...
challenging
419
thrombosis_prediction
I'm reviewing the 1991 lab records of the thrombosis cohort, checking whether heavy proteinuria went hand in hand with lower hematocrit that year, as a sign of anemia in kidney involvement. Among the laboratory tests done in 1991 that reported proteinuria of at least 300 mg/dL, what was the average hematocrit value? Pl...
SELECT ROUND(AVG(HCT), 2) AS average_hematocrit FROM Laboratory WHERE STRFTIME('%Y', Date) = '1991' AND CAST(REPLACE(`U-PRO`, '>=', '') AS REAL) >= 300
challenging
420
thrombosis_prediction
I'm putting together a care-setting summary of severe SLE cases for the rheumatology department. Among patients diagnosed with SLE, considering only those whose only diagnosis is SLE and who had abnormally high proteinuria, how many were admitted to the hospital and how many were followed at the outpatient clinic? Plea...
Abnormally high proteinuria means a proteinuria level of 30 or higher.
SELECT COUNT(DISTINCT CASE WHEN T1.Admission = '+' THEN T1.ID END) AS admitted_to_hospital, COUNT(DISTINCT CASE WHEN T1.Admission = '-' THEN T1.ID END) AS followed_at_outpatient_clinic FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Diagnosis = 'SLE' AND CAST(T2.`U-PRO` AS REAL) >= 30
challenging
421
thrombosis_prediction
How many patients in our thrombosis ward are followed at the outpatient clinic (rather than admitted) with a normal Rheumatoid Factor and no positive measure of degree of coagulation? Please give me a single number. For context: a normal Rheumatoid Factor is '-' or '+-', a positive measure of degree of coagulation is '...
SELECT COUNT(DISTINCT T1.ID) AS patient_count FROM Patient AS T1 WHERE T1.Admission = '-' AND T1.ID IN (SELECT ID FROM Laboratory WHERE RA IN ('-', '+-')) AND NOT EXISTS (SELECT 1 FROM Examination E WHERE E.ID = T1.ID AND (E.KCT = '+' OR E.RVVT = '+' OR E.LAC = '+'))
challenging
422
thrombosis_prediction
I'm reviewing our cohort and need to identify patients whose most recent laboratory sample on file was collected after 1 January 1997 (strictly later than that date) and whose most recent anti-Scl-70 result on file was normal. Please return only the patient IDs for these patients.
anti-Scl-70: anti-topoisomerase I antibody, an autoantibody measured in the laboratory. A normal anti-Scl-70 result is a result of 'negative' or 0.
WITH lab AS (SELECT ID, MAX(Date) AS LastDate FROM Laboratory GROUP BY ID), last_sc AS (SELECT s.ID AS ID, s.SC170 AS SC170 FROM Laboratory s WHERE s.SC170 IS NOT NULL AND s.Date = (SELECT MAX(s2.Date) FROM Laboratory s2 WHERE s2.ID = s.ID AND s2.SC170 IS NOT NULL)) SELECT l.ID FROM lab l JOIN last_sc c ON c.ID = l.ID ...
challenging
423
thrombosis_prediction
I'd like to know how many patients on record have both an abnormal anti-SSA antibody result and a positive proteinuria finding at some point in their record. Abnormal anti-SSA means any recorded test result other than negative or zero. Proteinuria counts as positive if any urine test on file returned a result other tha...
anti-SSA: anti-SSA antibody laboratory test; proteinuria: protein found in the urine
SELECT COUNT(*) AS patient_count FROM Patient AS T1 WHERE T1.ID IN (SELECT ID FROM Laboratory WHERE SSA IS NOT NULL AND SSA NOT IN ('negative', '0')) AND T1.ID IN (SELECT ID FROM Laboratory WHERE `U-PRO` IS NOT NULL AND `U-PRO` NOT IN ('-', '0'))
challenging
424
thrombosis_prediction
For a study of laboratory test patterns, I need to size a cohort. How many female patients have at least one anti-DNA antibody level below 8 (the upper bound of the normal range)? Any laboratory visit of the patient qualifies; there is no time scope. I just need that single count back.
anti-DNA level: the anti-DNA antibody concentration measured in the laboratory tests
SELECT COUNT(DISTINCT T1.ID) AS patient_count FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'F' AND CAST(T2.DNA AS REAL) < 8;
challenging
425
thrombosis_prediction
For patients admitted to the hospital, how many never had an alkaliphosphatase level above the normal ceiling in their lab results? I just need that single count.
A patient is admitted when their status is anything other than the outpatient-clinic code; the outpatient-clinic code is '-' and admitted is '+'. A normal alkaliphosphatase level is below 300; a level of 300 or more is above the normal ceiling.
SELECT COUNT(*) AS admitted_never_high_alp FROM Patient WHERE Admission <> '-' AND NOT EXISTS (SELECT 1 FROM Laboratory WHERE Laboratory.ID = Patient.ID AND ALP >= 300)
challenging
426
thrombosis_prediction
Among patients in the thrombosis prediction database whose creatinine level is normal (below 1.5), what is the highest anti-RNP antibody level recorded? Please return just that single number; if several measurements tie for the highest, the tied value is the answer.
Anti-RNP antibody = anti-ribonuclear protein antibody, measured by the laboratory panel.
SELECT MAX(CAST(T2.RNP AS REAL)) AS max_rnp_level FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CRE < 1.5
challenging
427
thrombosis_prediction
I'd like to see how severe anemia is distributed across the sexes in the registry. Please give me, for each sex, the number of patients of that sex who ever showed severe anemia on any lab test, with the rows labeled 'female' and 'male'.
Severe anemia means a hemoglobin value below 7.0 g/dL on a lab test.
SELECT CASE p.SEX WHEN 'F' THEN 'female' WHEN 'M' THEN 'male' END AS sex, COUNT(DISTINCT p.ID) AS severe_anemia_patients FROM Patient AS p INNER JOIN Laboratory AS l ON l.ID = p.ID WHERE l.HGB < 7.0 GROUP BY p.SEX HAVING p.SEX IN ('F','M')
challenging
428
thrombosis_prediction
Among the laboratory tests whose AST glutamic oxaloacetic transaminase (GOT) index was above the normal range (60 or higher), I want to find the test with the highest anti-ribonuclear protein reading. Please give me the patient's identification, the date of the laboratory test, and the anti-ribonuclear protein reading ...
AST glutamic oxaloacetic transaminase (GOT) index: a liver enzyme measurement; values of 60 or higher are considered above the normal range.
SELECT ID, Date, RNP FROM Laboratory WHERE GOT >= 60 AND CAST(RNP AS REAL) = (SELECT MAX(CAST(RNP AS REAL)) FROM Laboratory WHERE GOT >= 60)
challenging
429
thrombosis_prediction
I'm screening our thrombosis cohort for a study and need an eligibility count. How many patients born after 1980-01-01 had at least one abnormal fibrinogen result or at least one severe proteinuria result? A fibrinogen result is abnormal if it's below 150 or above 450; the normal range 150-450 is inclusive. Severe prot...
Urinalysis protein scale: '-' and '0' mean no protein, 'TR' means trace, grades '1','2','3','4' mean 1+ to 4+, where 3+ is about 300 mg/dl and 4+ about 1000 mg/dl or more; a plain number is a reading in mg/dl, and a '>=' prefix means 'or more'.
SELECT COUNT(DISTINCT p.ID) AS patient_count FROM Patient AS p JOIN Laboratory AS l ON p.ID = l.ID WHERE p.Birthday > '1980-01-01' AND ((l.FG < 150 OR l.FG > 450) OR (l.`U-PRO` IN ('3','4') OR CAST(replace(l.`U-PRO`,'>=','') AS REAL) >= 300))
challenging
430
thrombosis_prediction
In the thrombosis and autoimmune-disease cohort, I want to compare how often lactate dehydrogenase stays in the normal range between patients admitted to the hospital and patients followed at the outpatient clinic. Please give me one row per patient group showing the number of lactate dehydrogenase measurements within ...
The normal range for lactate dehydrogenase means a value below 500.
SELECT CASE WHEN P.Admission = '+' THEN 'admitted to the hospital' ELSE 'followed at the outpatient clinic' END AS patient_group, COUNT(*) AS normal_ldh_measurements FROM Patient AS P JOIN Laboratory AS L ON P.ID = L.ID WHERE P.Admission IN ('+', '-') AND L.LDH < 500 GROUP BY 1 ORDER BY CASE P.Admission WHEN '+' THEN 0...
challenging
431
thrombosis_prediction
For patients whose sex is not recorded in the registry, I need two counts for the annual quality report: how many have at least one laboratory result on file, and of those, how many have at least one laboratory result showing elevated total bilirubin. The report covers all dates.
A patient's sex is not recorded when the registry holds no sex entry for that patient. Total bilirubin of 2.0 or higher counts as elevated.
SELECT COUNT(DISTINCT T2.ID) AS patients_with_lab_results, COUNT(DISTINCT CASE WHEN T2.`T-BIL` >= 2.0 THEN T2.ID END) AS patients_with_elevated_bilirubin FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.SEX IS NULL OR T1.SEX = ''
challenging
432
thrombosis_prediction
For an audit, I need the number of admitted female patients born between 1945 and 1989 (inclusive) who have an ANA examination where the observed pattern is exactly P, with no other pattern alongside it. Please return just that single count.
ANA pattern: the pattern observed in the ANA examination, e.g. 'P' or 'P,S'; the admission mark starting with a plus indicates the patient was admitted.
SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T1.Admission LIKE '+%' AND T1.SEX = 'F' AND STRFTIME('%Y', T1.Birthday) BETWEEN '1945' AND '1989' AND T2.`ANA Pattern` = 'P'
challenging
433
thrombosis_prediction
I'm screening outpatient clinic patients with anemia for rheumatologic autoimmunity. Among patients who were followed as outpatients (rather than admitted to the hospital) and who ever had a hemoglobin value below 10 on any lab test, who showed the strongest anti-ribonuclear protein antibody response? Please return, fo...
Anti-ribonuclear protein refers to the antibody measured in the laboratory tests (anti-RNP).
SELECT p.ID, p.SEX, MAX(CAST(r.RNP AS REAL)) AS highest_level FROM Patient p JOIN Laboratory r ON r.ID = p.ID WHERE p.Admission = '-' AND EXISTS (SELECT 1 FROM Laboratory h WHERE h.ID = p.ID AND h.HGB < 10) GROUP BY p.ID, p.SEX HAVING MAX(CAST(r.RNP AS REAL)) = (SELECT MAX(CAST(r2.RNP AS REAL)) FROM Patient p2 JOIN Lab...
challenging
434
thrombosis_prediction
Among the patients in the thrombosis prediction data, how many have a first laboratory record showing both a normal glutamic oxaloacetic transaminase (GOT) level and an elevated anti-ribonuclear protein (RNP) concentration? By normal GOT I mean a value below 60, and by elevated RNP I mean a value above 10. By first lab...
GOT stands for glutamic oxaloacetic transaminase (also known as aspartate aminotransferase, AST); RNP stands for anti-ribonuclear protein.
SELECT COUNT(DISTINCT L.ID) FROM Laboratory AS L WHERE L.Date = (SELECT MIN(Date) FROM Laboratory WHERE ID = L.ID) AND L.GOT < 60 AND CAST(L.RNP AS REAL) > 10
challenging
435
thrombosis_prediction
I'm reviewing the current kidney involvement status of the thrombosis prediction cohort. For every patient who has had a proteinuria test, I need their patient identifier, sex, the date of their most recent proteinuria test, and the proteinuria level measured on that test. "Most recent" means the latest proteinuria tes...
A proteinuria test is a test that measures the level of protein in the urine; the proteinuria level is the result value it reports.
SELECT p.ID AS patient_id, p.SEX AS sex, l.Date AS most_recent_test_date, l.`U-PRO` AS proteinuria_level FROM Patient p JOIN Laboratory l ON l.ID = p.ID WHERE l.`U-PRO` IS NOT NULL AND l.Date = (SELECT MAX(l2.Date) FROM Laboratory l2 WHERE l2.ID = l.ID AND l2.`U-PRO` IS NOT NULL) ORDER BY p.ID
challenging
436
thrombosis_prediction
I'm screening the thrombosis cohort for a follow-up panel. Can you give me the patient ids of outpatients (patients followed at the outpatient clinic rather than admitted) whose creatinine phosphokinase is in the normal range (below 250) but whose anti-ribonuclear protein antibody level is above 4 (strictly greater tha...
SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CPK < 250 AND T1.Admission = '-' AND CAST(T2.RNP AS REAL) > 4
challenging
437
thrombosis_prediction
I'd like to know how many patients in the cohort have a positive anti-ribonuclear protein (RNP) result but no thrombosis. A positive RNP result means the anti-ribonuclear protein level is above 0, and no thrombosis means the thrombosis degree is 0. Please return just the number of such patients.
SELECT COUNT(DISTINCT T1.ID) FROM Examination AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE CAST(T2.RNP AS REAL) > 0 AND T1.Thrombosis = 0
challenging
438
thrombosis_prediction
I'm reviewing patients with an elevated anti-ribonuclear protein result. Among patients who ever had an anti-ribonuclear protein result of 16 or higher, I want to follow up the three whose liver enzymes stayed in the normal range. The normal range for GPT is below 60. For each patient, take their highest GPT value amon...
GPT stands for glutamic pyruvic transaminase, a liver enzyme; anti-ribonuclear protein is an autoantibody measured in laboratory tests.
SELECT T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GPT < 60 AND T1.ID IN (SELECT ID FROM Laboratory WHERE CAST(RNP AS REAL) >= 16) GROUP BY T1.ID ORDER BY MAX(T2.GPT) DESC, T1.ID ASC LIMIT 3
challenging
439
thrombosis_prediction
I'm trying to size a subgroup in the thrombosis cohort: how many female patients had a normal prothrombin time (below 14 seconds) along with an elevated anti-ribonuclear protein level (16 or higher)? Please use the prothrombin time and anti-ribonuclear protein level from the same laboratory record for each patient. I j...
Normal prothrombin time: below 14 seconds. Elevated anti-ribonuclear protein: a measured level of 16 or higher.
SELECT COUNT(DISTINCT T1.ID) AS patient_count FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'F' AND T2.PT < 14 AND CAST(T2.RNP AS REAL) >= 16
challenging
440
thrombosis_prediction
Among inpatients (admission marked '+'), find the laboratory anti-DNA antibody test with the highest recorded level, and report the patient's age in completed years at that test date and the patient's diagnosis. If several tests share the highest level, use the one with the earliest test date.
An inpatient is a patient admitted to the hospital: the Admission record is marked '+' (a '-' marks an outpatient followed at the clinic). Age in completed years means the age at the last birthday reached on or before the test date. The anti-DNA antibody level is a laboratory reading reported alongside the other antibo...
WITH cand AS (SELECT p.Diagnosis, CAST(STRFTIME('%Y', l.Date) AS INTEGER) - CAST(STRFTIME('%Y', p.Birthday) AS INTEGER) - CASE WHEN SUBSTR(l.Date, 6, 5) < SUBSTR(p.Birthday, 6, 5) THEN 1 ELSE 0 END AS age, CAST(l.DNA AS REAL) AS level, l.Date AS test_date FROM Patient AS p JOIN Laboratory AS l ON p.ID = l.ID WHERE l.DN...
challenging
441
thrombosis_prediction
I need to find lupus patients with liver lab abnormalities. Can you give me the ID and sex of every patient who has at least one total bilirubin (T-BIL) result at or above the upper normal limit of 1.2 mg/dL, and who has a confirmed diagnosis of systemic lupus erythematosus (SLE)? SLE counts if it's among the patient's...
T-BIL: total bilirubin; SLE: systemic lupus erythematosus; susp.: suspected, not a confirmed diagnosis
SELECT p.ID, p.SEX FROM Patient AS p WHERE p.ID IN (SELECT ID FROM Laboratory WHERE "T-BIL" >= 1.2) AND instr(',' || REPLACE(p.Diagnosis, ' ', '') || ',', ',' || 'SLE' || ',') > 0 ORDER BY p.SEX, p.ID;
challenging
442
thrombosis_prediction
I'm reviewing how often older female patients show elevated anti-RNP antibody results, split by whether they were admitted to the hospital or followed at the outpatient clinic. For female patients aged at least 50 as of 2026-10-09, please give me a two-row breakdown by care setting (admitted to the hospital vs. followe...
anti-RNP: anti-ribonuclear protein antibody, measured in laboratory results; admission marker: the patient's recorded admission sign.
SELECT CASE WHEN p.Admission = '+' THEN 'admitted to the hospital' ELSE 'followed at the outpatient clinic' END AS care_setting, SUM(CASE WHEN EXISTS (SELECT 1 FROM Laboratory AS l WHERE l.ID = p.ID AND CAST(l.RNP AS REAL) >= 4) THEN 1 ELSE 0 END) AS patients_with_rnp_at_least_4, SUM(CASE WHEN EXISTS (SELECT 1 FROM Lab...
challenging
443
thrombosis_prediction
I'm putting together a cohort summary and need one number: how many patients followed at the outpatient clinic (admission marker '-') have a most recent IgG lab result of 2000 or higher? By most recent, I mean the IgG measurement with the greatest laboratory date for that patient - since a patient has at most one lab r...
WITH latest_igg AS (SELECT ID, MAX(Date) AS LastDate FROM Laboratory WHERE IGG IS NOT NULL GROUP BY ID) SELECT COUNT(*) AS patient_count FROM Patient AS p JOIN latest_igg AS li ON li.ID = p.ID JOIN Laboratory AS l ON l.ID = li.ID AND l.Date = li.LastDate WHERE p.Admission = '-' AND l.IGG >= 2000
challenging
444
thrombosis_prediction
Among all patients diagnosed with systemic lupus erythematosus, I want to find the patient whose anti-DNA test result was the strongest ever recorded for that disease. Please report the patient's identifier, the patient's diagnosis, and that patient's highest anti-DNA test result, using the number exactly as the test w...
Systemic lupus erythematosus (SLE) is an autoimmune disease; anti-DNA is an antibody test reported as a number.
WITH ranked AS (SELECT p.ID AS patient_id, p.Diagnosis AS diagnosis, l.DNA AS highest_anti_dna, ROW_NUMBER() OVER (PARTITION BY p.ID ORDER BY CAST(l.DNA AS REAL) DESC, l.Date DESC) AS rn FROM Patient p INNER JOIN Laboratory l ON p.ID = l.ID WHERE p.Diagnosis LIKE '%SLE%' AND l.DNA IS NOT NULL), best AS (SELECT patient_...
challenging
445
thrombosis_prediction
For our thrombosis study cohort, I'd like to know how often patients have a normal IgG status at their most recent check, broken down by care setting. Please give me, for patients admitted to the hospital and for patients followed at the outpatient clinic, the percentage of that setting's patients whose most recent IgG...
An IgG measurement is considered normal when it is above 900 and below 2000.
WITH latest AS (SELECT ID, IGG, ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Date DESC) AS rn FROM Laboratory WHERE IGG IS NOT NULL) SELECT CASE WHEN p.Admission = '+' THEN 'admitted to the hospital' ELSE 'followed at the outpatient clinic' END AS care_setting, ROUND(100.0 * SUM(CASE WHEN l.IGG > 900 AND l.IGG < 2000 TH...
challenging
446
thrombosis_prediction
In the thrombosis prediction cohort, I'd like to know whether the female predominance I saw for strongly positive anti-RNP results across follow-up also holds at patients' current status. Please give me a single integer: the number of female patients whose most recent visit shows a strongly positive anti-RNP result, mi...
anti-ribonuclear protein (RNP): an autoantibody measured in the laboratory work-up; visit: a date on which the patient's laboratory tests were performed
WITH latest AS (SELECT ID, MAX(Date) AS MaxDate FROM Laboratory GROUP BY ID) SELECT COUNT(DISTINCT CASE WHEN p.SEX = 'F' AND CAST(l.RNP AS REAL) >= 32 THEN p.ID END) - COUNT(DISTINCT CASE WHEN p.SEX = 'M' AND CAST(l.RNP AS REAL) >= 32 THEN p.ID END) AS female_minus_male FROM Patient AS p JOIN latest AS la ON p.ID = la....
challenging
447
thrombosis_prediction
In the thrombosis prediction cohort, I want to gauge how often the most recent anti-ribonuclear protein measurement among female patients was markedly elevated while CPK stayed low at that same measurement. Please give me a single integer: the number of female patients whose most recent anti-ribonuclear protein titer w...
Anti-ribonuclear protein is an autoantibody measured as a titer in the blood; a negative result means the antibody was not detected.
SELECT COUNT(DISTINCT p.ID) AS female_patients FROM Patient AS p JOIN Laboratory AS l ON l.ID = p.ID WHERE p.SEX = 'F' AND l.RNP IS NOT NULL AND l.Date = (SELECT MAX(l2.Date) FROM Laboratory AS l2 WHERE l2.ID = p.ID AND l2.RNP IS NOT NULL) AND CAST(l.RNP AS REAL) > 64 AND l.CPK < 250
challenging
448
thrombosis_prediction
I'm preparing a capacity report for the lupus service. Among the patients whose profile lists a confirmed SLE diagnosis (not just suspected), I need: (1) how many were admitted to the hospital as inpatients, (2) how many were followed at the outpatient clinic, and (3) what percentage of the confirmed-SLE patients who w...
SLE means systemic lupus erythematosus. A disease name followed by 'susp' (e.g., 'SLE susp') means only suspected, not confirmed, and does not count.
SELECT SUM(CASE WHEN Admission = '+' THEN 1 ELSE 0 END) AS inpatients, SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END) AS outpatients, ROUND(100.0 * SUM(CASE WHEN Admission = '+' THEN 1 ELSE 0 END) / SUM(CASE WHEN Admission IN ('+', '-') THEN 1 ELSE 0 END), 2) AS inpatient_pct FROM Patient WHERE Diagnosis LIKE '%SLE%'...
challenging
449
thrombosis_prediction
I'm putting together a renal-involvement review. Could you pull the demographics of patients who show both marked tissue damage and clinically significant proteinuria? Specifically, I need the patient ID, sex, and birthday of every patient who has at least one LDH result of 500 or higher and at least one urinary protei...
Urinary protein is reported in mg/dL; a dipstick grade may carry the equivalent concentration in mg/dL in parentheses, e.g. '+2(100)' is 100 mg/dL. A result written as '>=' followed by a value means at least that many mg/dL, e.g. '>=300' is 300 mg/dL or more. 'TR' means a trace and '-' means none detected; any other ma...
SELECT DISTINCT p.ID, p.SEX, p.Birthday FROM Patient AS p WHERE EXISTS (SELECT 1 FROM Laboratory AS l WHERE l.ID = p.ID AND l.LDH >= 500) AND EXISTS (SELECT 1 FROM Laboratory AS u WHERE u.ID = p.ID AND CASE WHEN u.`U-PRO` LIKE '%(%' THEN CAST(substr(u.`U-PRO`, instr(u.`U-PRO`, '(')+1, instr(u.`U-PRO`, ')')-instr(u.`U-P...
challenging
450
thrombosis_prediction
Some registered patients have unknown thrombosis status because no examination has ever been recorded under their patient number. How many of these patients are women and how many are men? Please give me one row per sex with the sex of the patients and the number of such patients of that sex, and nothing else.
F is the code for female and M is the code for male in the patient profile.
SELECT P.SEX AS sex, COUNT(*) AS patients FROM Patient P WHERE P.SEX IN ('F','M') AND NOT EXISTS (SELECT 1 FROM Examination E WHERE E.ID = P.ID) GROUP BY P.SEX ORDER BY P.SEX
challenging
451
thrombosis_prediction
I need the number of female patients whose first visit to the hospital fell in 1998 (1 January 1998 through 31 December 1998) and who were admitted to the hospital. Only count patients whose sex is recorded as female; if there is no sex entry, don't count them.
An admission mark beginning with a plus sign means the patient was admitted to the hospital; a minus sign means the patient was followed at the outpatient clinic.
SELECT COUNT(*) FROM `Patient` WHERE strftime('%Y', `First Date`) = '1998' AND SEX = 'F' AND `Admission` LIKE '+%'
challenging
452
thrombosis_prediction
I'm reviewing confirmed SLE cases for a study of neurologic involvement. Among patients whose examination lists SLE among the diagnosed diseases and who have a symptom recorded at such an examination, I need the case detail of the youngest such patient. Please send me the symptom recorded at that qualifying examination...
SLE is systemic lupus erythematosus. A disease name followed by 'susp' means the disease was only suspected, not diagnosed.
WITH target AS (SELECT 'SLE' AS d) SELECT e.Symptoms, p.Diagnosis AS overall_diagnosis FROM Patient AS p JOIN Examination AS e ON e.ID = p.ID WHERE p.Birthday IS NOT NULL AND e.Symptoms IS NOT NULL AND TRIM(e.Symptoms) <> '' AND EXISTS (SELECT 1 FROM target WHERE REPLACE(',' || REPLACE(e.Diagnosis, ' ', '') || ',', ','...
challenging
453
thrombosis_prediction
I'm auditing inpatient intake during the February 1998 admission wave. Among patients first seen at the hospital in the second half of February 1998 (visit date from 15 to 28 February 1998), find the oldest inpatient at first presentation and give me that patient's diagnosis only. If two patients tie in age, use the on...
'Inpatient' means the patient was admitted to the hospital rather than followed at the outpatient clinic, regardless of whether the record notes extra detail about the admission.
SELECT p.Diagnosis FROM Patient AS p WHERE p.`First Date` >= '1998-02-15' AND p.`First Date` <= '1998-02-28' AND p.Admission LIKE '+%' ORDER BY p.Birthday ASC, p.ID ASC LIMIT 1
challenging
454
thrombosis_prediction
I'm summarizing anti-cardiolipin IgM levels for lupus patients. What was the average anti-cardiolipin IgM concentration across examinations performed between 1993-10-01 and 1993-10-31 (both days inclusive) in which systemic lupus erythematosus (SLE) was diagnosed? Please round the average to 1 decimal place.
SLE = systemic lupus erythematosus
SELECT ROUND(AVG(e."aCL IgM"), 1) AS avg_aCL_IgM FROM Examination AS e WHERE e."Examination Date" BETWEEN '1993-10-01' AND '1993-10-31' AND instr(',' || REPLACE(e.Diagnosis, ' ', '') || ',', ',' || 'SLE' || ',') > 0
challenging
455
thrombosis_prediction
How many patients in the thrombosis prediction cohort have a diagnosis of psoriatic arthritis? The count should cover every patient ever recorded in the registry, with no restriction to a time period or follow-up status. I just need that single number.
Psoriatic arthritis: a chronic inflammatory joint and skin disease belonging to the rheumatic diagnoses.
SELECT COUNT(*) AS patient_count FROM Patient WHERE UPPER(REPLACE(Diagnosis, ' ', '')) = UPPER(REPLACE('Psoriatic arthritis', ' ', ''))
challenging
456
thrombosis_prediction
I need to size a comparison group for my study of liver-enzyme abnormalities. How many patients in the registry have never had an ALT result above the normal range? Please give me the count broken down by sex: the number of male patients and the number of female patients. Every patient in the registry counts, including...
ALT is measured by the GPT laboratory value; a GPT result of 60 or higher exceeds the normal range.
SELECT P.SEX AS sex, COUNT(*) AS patient_count FROM Patient P WHERE P.SEX IN ('M','F') AND NOT EXISTS (SELECT 1 FROM Laboratory L WHERE L.ID = P.ID AND L.GPT >= 60) GROUP BY P.SEX ORDER BY P.SEX
challenging
457
thrombosis_prediction
For patients with at least one red-blood-cell result below 3.5 (RBC), I need a breakdown by care setting: how many patients were admitted to the hospital (+) versus followed at the outpatient clinic (-), and the average completed age of each group on 2026-10-09, rounded to one decimal place. Age means completed years o...
Red-blood-cell result below 3.5 (RBC); admission status + marks a patient admitted to the hospital, - marks a patient followed at the outpatient clinic.
SELECT p.Admission AS care_setting, COUNT(*) AS patient_count, ROUND(AVG(CAST(strftime('%Y','2026-10-09') AS INTEGER) - CAST(strftime('%Y', p.Birthday) AS INTEGER) - CASE WHEN strftime('%m-%d', '2026-10-09') < strftime('%m-%d', p.Birthday) THEN 1 ELSE 0 END), 1) AS average_age FROM Patient AS p WHERE p.Admission IN ('+...
challenging
458
thrombosis_prediction
Among the patients who have laboratory test records on file, how many are female and how many are male? Please give me one line for the female patients and one line for the male patients, each showing the sex and the number of patients of that sex.
SELECT p.SEX AS sex, COUNT(DISTINCT p.ID) AS patient_count FROM Patient p JOIN Laboratory l ON l.ID = p.ID WHERE p.SEX IN ('F','M') GROUP BY p.SEX
challenging
459
thrombosis_prediction
I'm studying antiphospholipid antibodies in Sjögren's syndrome (SJS). Could you tell me the average anti-cardiolipin IgM concentration among SJS patients, rounded to two decimal places? To clarify: use only patients with an established SJS diagnosis recorded at the patient level (a diagnosis marked 'susp', such as 'SJS...
SJS is the abbreviation used for Sjögren's syndrome; a diagnosis marked 'susp' (e.g. 'SJS susp') is only a suspicion of the disease, not an established diagnosis.
WITH RECURSIVE tokens AS (SELECT ID, '' AS tok, COALESCE (Diagnosis, '') || ',' AS rest FROM Patient UNION ALL SELECT ID, trim(substr(rest, 1, instr(rest, ',') - 1)), substr(rest, instr(rest, ',') + 1) FROM tokens WHERE rest <> '') SELECT ROUND(AVG(CASE WHEN e."aCL IgM" > 0 THEN e."aCL IgM" END), 2) AS avg_aCL_IgM FROM...
challenging
460
thrombosis_prediction
How many female patients have a Sjögren's syndrome diagnosis recorded in a medical examination? Please count across the full examination history with no date restriction, and note that suspected cases don't count—only an actual SjS diagnosis should be included. I just need that single number.
SjS is the standard medical abbreviation for Sjögren's syndrome, and the diagnosis is recorded under that abbreviation.
SELECT COUNT(DISTINCT T1.ID) AS n_female_sjs_patients FROM Patient AS T1 JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'F' AND (',' || REPLACE(T2.Diagnosis, ' ', '') || ',') LIKE ('%' || ',' || 'SjS' || ',' || '%');
challenging
461
thrombosis_prediction
How many patients who were never admitted to the hospital (outpatient follow-up only) had at least one normal anti-ribonuclear protein (RNP) result? A normal RNP result means the test found no anti-ribonuclear protein antibody: a negative result, or a measured value of zero. I just need a single number.
anti-ribonuclear protein (RNP): an antibody test
SELECT COUNT(DISTINCT p.ID) AS patient_count FROM Patient AS p JOIN Laboratory AS l ON p.ID = l.ID WHERE p.Admission = '-' AND l.RNP IN ('negative', '0')
challenging
462
thrombosis_prediction
I'd like to know, among patients who have at least one normal anti-SM laboratory result (recorded as 'negative' or '0') and whose examinations show no thrombosis, how many have ever had significant proteinuria on any laboratory record. Significant proteinuria means 30 mg/dl or more; '-' and 'TR' count as no proteinuria...
anti-SM: normal is recorded as 'negative' or '0'; proteinuria is measured semi-quantitatively as '-', 'TR', or the approximate daily urinary protein excretion in mg/dl
SELECT COUNT(*) AS patient_count FROM Patient AS p WHERE EXISTS (SELECT 1 FROM Laboratory AS l WHERE l.ID = p.ID AND l.SM IN ('negative', '0')) AND EXISTS (SELECT 1 FROM Examination AS e WHERE e.ID = p.ID AND e.Thrombosis = 0) AND NOT EXISTS (SELECT 1 FROM Examination AS e WHERE e.ID = p.ID AND e.Thrombosis <> 0) AND E...
challenging
463
thrombosis_prediction
Which patients followed at the outpatient clinic have both an abnormal red blood cell count and a positive anti-ribonuclear protein antibody result? Please return the patient IDs. Note: the two findings don't need to be from the same laboratory visit - a patient qualifies if at least one lab test shows an abnormal RBC ...
SELECT T1.ID FROM Patient T1 WHERE T1.Admission = '-' AND EXISTS (SELECT 1 FROM Laboratory L1 WHERE L1.ID = T1.ID AND (L1.RBC <= 3.5 OR L1.RBC >= 6)) AND EXISTS (SELECT 1 FROM Laboratory L2 WHERE L2.ID = T1.ID AND CAST(L2.RNP AS REAL) > 0) ORDER BY T1.ID
challenging
464
thrombosis_prediction
In our autoimmune-cohort registry, I'm profiling young patients with strongly positive anti-RNP findings. What is the average age, in years, of the patients who were younger than 70 as of 2026-10-09 and who have at least one anti-RNP result of 64 or higher? Please give the average as a single number to one decimal plac...
anti-ribonuclear protein (anti-RNP) result: the reading recorded for a patient's anti-RNP test in the laboratory record
SELECT ROUND(AVG(CAST(substr('2026-10-09',1,4) AS INTEGER) - CAST(substr(p.Birthday,1,4) AS INTEGER) - (substr('2026-10-09',6) < substr(p.Birthday,6))), 1) AS average_age FROM Patient AS p WHERE (CAST(substr('2026-10-09',1,4) AS INTEGER) - CAST(substr(p.Birthday,1,4) AS INTEGER) - (substr('2026-10-09',6) < substr(p.Bir...
challenging
465
thrombosis_prediction
I'd like a single number: how many female patients in the thrombosis prediction data have a laboratory record showing a normal white blood cell count, an abnormal fibrinogen level, and an anti-ribonuclear protein (RNP) reading above 15, considering all recorded laboratory dates?
A normal white blood cell count means strictly between 3.5 and 9.0; an abnormal fibrinogen level means at most 150 or at least 450.
SELECT COUNT(DISTINCT p.ID) FROM Patient AS p JOIN Laboratory AS l ON l.ID = p.ID WHERE p.SEX = 'F' AND l.WBC > 3.5 AND l.WBC < 9.0 AND (l.FG <= 150 OR l.FG >= 450) AND CAST(l.RNP AS REAL) > 15
challenging
466
thrombosis_prediction
As part of our clinical audit I'm profiling patients born between 1936 and 1956 inclusive who never had a creatinine phosphokinase (CPK) result above the normal range. A CPK of 250 or higher counts as above the normal range, and patients with no CPK results on record count as never having exceeded it. For that group, p...
Creatinine phosphokinase (CPK) of 250 or higher is above the normal range.
SELECT ROUND(CAST(SUM(CASE WHEN SEX = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / SUM(CASE WHEN SEX IN ('M','F') THEN 1 ELSE 0 END), 1) AS percentage FROM Patient WHERE STRFTIME('%Y', Birthday) BETWEEN '1936' AND '1956' AND NOT EXISTS (SELECT 1 FROM Laboratory WHERE Laboratory.ID = Patient.ID AND Laboratory.CPK >= 250)
challenging
467
thrombosis_prediction
I'm preparing a case series on early renal involvement and need to size my cohort. How many patients were under age 50 on the day of a laboratory test performed between 1 January 1981 and 31 December 1986 inclusive, had a platelet count from 100 through 400 at that test, and showed proteinuria at that test? Age means c...
A patient showed proteinuria at a test when that test's dipstick reading reports protein: a dash or zero means no protein was found, a number is the amount of protein found, TR stands for trace protein, and a reading written in percent signs is the dipstick saturated, the strongest reading.
SELECT COUNT(DISTINCT p.ID) AS patient_count FROM Patient AS p JOIN Laboratory AS l ON l.ID = p.ID WHERE SUBSTR(l.Date, 1, 4) BETWEEN '1981' AND '1986' AND l.PLT BETWEEN 100 AND 400 AND p.Birthday IS NOT NULL AND (CAST(SUBSTR(l.Date, 1, 4) AS INTEGER) - CAST(SUBSTR(p.Birthday, 1, 4) AS INTEGER) - CASE WHEN SUBSTR(l.Dat...
challenging
468
toxicology
Among molecules containing at least one single bond, what is the average number of oxygen atoms per molecule? Include molecules with no oxygen and round to four decimal places.
The '-' bond-type symbol denotes a single bond.
WITH molecules AS ( SELECT DISTINCT molecule_id FROM bond WHERE bond_type = '-' ), oxygen AS ( SELECT molecule_id, COUNT(*) AS n FROM atom WHERE element = 'o' GROUP BY molecule_id ) SELECT ROUND(AVG(COALESCE(oxygen.n, 0)), 4) FROM molecules LEFT JOIN oxygen ON oxygen.molecule_id = molecules.molecule_id
moderate
469
toxicology
Among carcinogenic molecules with at least one single bond, what is the average number of single bonds per molecule?
In this dataset, '+' denotes a carcinogenic molecule and '-' denotes a single bond.
SELECT AVG(single_bond_count) FROM (SELECT b.molecule_id, COUNT(*) AS single_bond_count FROM bond AS b JOIN molecule AS m ON m.molecule_id = b.molecule_id WHERE m.label = '+' AND b.bond_type = '-' GROUP BY b.molecule_id) AS per_molecule
challenging
470
toxicology
Which elements have the fewest atom occurrences across non-carcinogenic molecules? Include all elements tied for the minimum.
A '-' carcinogenicity label means non-carcinogenic.
WITH counts AS ( SELECT a.element, COUNT(*) AS n FROM atom AS a JOIN molecule AS m ON m.molecule_id = a.molecule_id WHERE m.label = '-' GROUP BY a.element ) SELECT element FROM counts WHERE n = (SELECT MIN(n) FROM counts) ORDER BY element
challenging
471
toxicology
How many distinct iodine atoms and distinct sulfur atoms, respectively, participate in at least one single bond?
The '-' bond-type symbol denotes a single bond.
SELECT COUNT(DISTINCT CASE WHEN T1.element = 'i' THEN T1.atom_id ELSE NULL END) AS iodine_nums , COUNT(DISTINCT CASE WHEN T1.element = 's' THEN T1.atom_id ELSE NULL END) AS sulfur_nums FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN bond AS T3 ON T2.bond_id = T3.bond_id WHERE T3.bond_ty...
challenging
472
toxicology
Among carcinogenic molecules, what percentage contain no fluorine atoms? Round to two decimal places.
A '+' carcinogenicity label means carcinogenic.
SELECT ROUND(100.0 * SUM(CASE WHEN NOT EXISTS ( SELECT 1 FROM atom AS a WHERE a.molecule_id = m.molecule_id AND a.element = 'f' ) THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 2) FROM molecule AS m WHERE m.label = '+'
challenging
473
toxicology
What is the most common bond type in molecule TR010, and is that molecule carcinogenic? Return the bond type and YES or NO.
In this dataset, a molecule labeled '+' is carcinogenic; a molecule labeled '-' is not.
SELECT b.bond_type, CASE WHEN m.label = '+' THEN 'YES' ELSE 'NO' END FROM bond AS b JOIN molecule AS m ON m.molecule_id = b.molecule_id WHERE b.molecule_id = 'TR010' GROUP BY b.bond_type, m.label ORDER BY COUNT(*) DESC, b.bond_type LIMIT 1
challenging
474
toxicology
What are the bonds that have phosphorus and nitrogen as their atom elements?
SELECT T2.bond_id FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id IN (SELECT T3.bond_id FROM connected AS T3 INNER JOIN atom AS T4 ON T3.atom_id = T4.atom_id WHERE T4.element = 'p') AND T1.element = 'n'
moderate
475
toxicology
List the distinct elements of atoms that do not participate in any bond.
SELECT DISTINCT a.element FROM atom AS a WHERE a.atom_id NOT IN ( SELECT atom_id FROM connected UNION SELECT atom_id2 FROM connected ) ORDER BY a.element
challenging
476
toxicology
How many atoms occur in molecules that have at least one triple bond and at least one phosphorus or bromine atom?
The '#' bond-type symbol denotes a triple bond.
WITH triple AS (SELECT DISTINCT molecule_id FROM bond WHERE bond_type = '#'), hetero AS (SELECT DISTINCT molecule_id FROM atom WHERE element IN ('p', 'br')), qualified AS (SELECT t.molecule_id FROM triple AS t JOIN hetero AS h ON h.molecule_id = t.molecule_id) SELECT COUNT(*) FROM atom AS a JOIN qualified AS q ON q.mol...
moderate
477
toxicology
Among all atoms in molecules containing at least one single bond, what percentage are chlorine atoms? Round to four decimal places.
The '-' bond-type symbol denotes a single bond.
WITH molecules AS ( SELECT DISTINCT molecule_id FROM bond WHERE bond_type = '-' ) SELECT ROUND(100.0 * SUM(CASE WHEN a.element = 'cl' THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 4) FROM molecules AS m JOIN atom AS a ON a.molecule_id = m.molecule_id
challenging
478
toxicology
What fraction of all atoms in molecule TR006 are hydrogen? Give the fraction and the molecule's recorded carcinogenicity label.
WITH SubQuery AS (SELECT DISTINCT T1.atom_id, T1.element, T1.molecule_id, T2.label FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.molecule_id = 'TR006') SELECT CAST(COUNT(CASE WHEN element = 'h' THEN atom_id ELSE NULL END) AS REAL) / (CASE WHEN COUNT(atom_id) = 0 THEN NULL ELSE CO...
challenging
479
toxicology
I want to know whether molecular saturation is associated with carcinogenicity in our compound library. Please report, for molecules in which every bond is a single bond: the number of carcinogenic molecules minus the number of non-carcinogenic molecules. And for all other molecules: the same difference (carcinogenic c...
In the labels, '+' indicates a carcinogenic molecule and '-' indicates a non-carcinogenic molecule; for bond types, '-' indicates a single bond.
SELECT (SELECT SUM(CASE WHEN m.label = '+' THEN 1 ELSE -1 END) FROM molecule m WHERE NOT EXISTS (SELECT 1 FROM bond b WHERE b.molecule_id = m.molecule_id AND b.bond_type <> '-')) AS diff_molecules_with_only_single_bonds, (SELECT SUM(CASE WHEN m.label = '+' THEN 1 ELSE -1 END) FROM molecule m WHERE EXISTS (SELECT 1 FROM...
challenging
480
toxicology
In our toxicology library, how many carbon-carbon pairs joined by a double bond are there in total across the carcinogenic compounds? I want a single number for the whole library.
A compound is carcinogenic when its label is '+' and non-carcinogenic when its label is '-'. In the bond notation, '-' is a single bond, '=' is a double bond, and '#' is a triple bond.
SELECT COUNT(*) AS num_pairs FROM connected AS c JOIN bond AS b ON b.bond_id = c.bond_id JOIN molecule AS m ON m.molecule_id = b.molecule_id JOIN atom AS a1 ON a1.atom_id = c.atom_id JOIN atom AS a2 ON a2.atom_id = c.atom_id2 WHERE m.label = '+' AND b.bond_type = '=' AND a1.element = 'c' AND a2.element = 'c' AND c.atom...
challenging
481
toxicology
Among the molecules labeled '+' (carcinogenic), which chemical element is the most common among the atoms that take part in at least one bond? Also give the percentage of all atoms in those '+' molecules that this element accounts for, rounded to two decimal places. Count the percentage over every atom of the '+' molec...
WITH plus_atoms AS (SELECT a.atom_id, a.element FROM atom a JOIN molecule m ON m.molecule_id = a.molecule_id WHERE m.label = '+'), bonded AS (SELECT atom_id, element FROM plus_atoms WHERE atom_id IN (SELECT atom_id FROM connected) OR atom_id IN (SELECT atom_id2 FROM connected)), bonded_counts AS (SELECT element, COUNT(...
challenging
482
toxicology
For the molecule containing atom TR041_10, I'd like to know the molecule id, whether it's carcinogenic (YES or NO), and the number of multiple bonds in that molecule. Please use the rule that a molecule labeled '+' is carcinogenic (YES) and one labeled '-' is not (NO).
SELECT T2.molecule_id, IIF(T2.label = '+', 'YES', 'NO') AS flag_carcinogenic, COUNT(T3.bond_id) AS multiple_bonds FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T3.molecule_id = T2.molecule_id WHERE T1.atom_id = 'TR041_10' AND T3.bond_type <> '-' GROUP BY T2.molecu...
challenging
483
toxicology
For the carcinogenic molecules in the toxicology database, how many carbon-carbon bonds are there of each bond type (single, double, and triple)? Please give me the bond type and the corresponding count.
A molecule labelled '+' is carcinogenic. Bond types are recorded as follows: a single bond as '-', a double bond as '=', and a triple bond as '#'. A carbon-carbon bond is a bond whose two bonded atoms are both carbon.
SELECT b.bond_type, COUNT(DISTINCT c.bond_id) AS bond_count FROM connected c JOIN atom a1 ON a1.atom_id = c.atom_id JOIN atom a2 ON a2.atom_id = c.atom_id2 JOIN bond b ON b.bond_id = c.bond_id JOIN molecule m ON m.molecule_id = b.molecule_id WHERE a1.element = 'c' AND a2.element = 'c' AND m.label = '+' GROUP BY b.bond_...
challenging
484
toxicology
I want to know how widely chlorine atoms bond to other atoms across the toxicology database. Please give me a single number: the count of atoms that bond with chlorine atoms. Nothing else.
Chlorine means the element recorded under the code cl.
SELECT COUNT(DISTINCT CASE WHEN a1.element = 'cl' THEN c.atom_id2 ELSE c.atom_id END) AS bonded_atoms FROM connected AS c JOIN atom AS a1 ON c.atom_id = a1.atom_id JOIN atom AS a2 ON c.atom_id2 = a2.atom_id WHERE a1.element = 'cl' OR a2.element = 'cl'
challenging
485
toxicology
I'm studying the immediate chemical environment of sulfur atoms in carcinogenic molecules. Please tell me, as a single number, how many atoms are directly bonded to a sulfur atom in carcinogenic molecules. A molecule labeled '+' is carcinogenic; a molecule labeled '-' is not.
Sulfur refers to the element 's'. A direct bond is a bond between two atoms.
SELECT COUNT(DISTINCT T2.atom_id2) AS atom_count FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN molecule AS M ON T1.molecule_id = M.molecule_id WHERE T1.element = 's' AND M.label = '+';
challenging
486
toxicology
I'm compiling bond records of unusual carcinogenic molecules for a structural alert review. Please find the bonds that belong to carcinogenic molecules (labelled '+') that contain an element recorded for no other molecule in the dataset. Note that this search covers the whole dataset, so an element counts as belonging ...
A '+' label means carcinogenic.
SELECT T1.bond_id, T1.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+' AND EXISTS (SELECT 1 FROM atom AS a WHERE a.molecule_id = T1.molecule_id AND a.element IN (SELECT element FROM atom GROUP BY element HAVING COUNT(DISTINCT molecule_id) = 1))
challenging
487
toxicology
I'm building a control group of nitrogen-containing structures for a carcinogenicity review. How many molecules in the database contain at least one nitrogen atom, where none of those nitrogen atoms takes part in a double bond or a triple bond? A nitrogen held only by single bonds is fine; any nitrogen in a double or t...
Nitrogen refers to the element code 'n'; '=' denotes a double bond; '#' denotes a triple bond; '-' denotes a single bond.
SELECT COUNT(*) AS number_of_molecules FROM molecule AS m WHERE EXISTS (SELECT 1 FROM atom AS a WHERE a.molecule_id = m.molecule_id AND a.element = 'n') AND NOT EXISTS (SELECT 1 FROM atom AS a2 INNER JOIN connected AS c ON c.atom_id = a2.atom_id OR c.atom_id2 = a2.atom_id INNER JOIN bond AS b ON b.bond_id = c.bond_id W...
challenging
488
toxicology
In the toxicology database, how many atoms are bonded to chlorine atoms, taken across all molecules? I want a single number. By chlorine I mean the element 'cl'.
cl: chlorine
SELECT COUNT(DISTINCT T1.atom_id) AS bonded_atom_count FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id2 = T2.atom_id WHERE T2.element = 'cl'
challenging
489
toxicology
For a report on structural features of carcinogenic compounds, I'm looking at compounds that form a triple bond. Among those, what percent are labeled carcinogenic and what percent are labeled non-carcinogenic, each rounded to two decimal places? The two percents should sum to 100, apart from rounding.
Label '+' means carcinogenic; label '-' means non-carcinogenic.
SELECT ROUND(CAST(COUNT(DISTINCT CASE WHEN m.label = '+' THEN b.molecule_id END) AS REAL) * 100 / COUNT(DISTINCT b.molecule_id), 2) AS pct_carcinogenic, ROUND(CAST(COUNT(DISTINCT CASE WHEN m.label = '-' THEN b.molecule_id END) AS REAL) * 100 / COUNT(DISTINCT b.molecule_id), 2) AS pct_non_carcinogenic FROM bond b JOIN m...
challenging
490
toxicology
I'm characterizing how strongly rare chemical elements are integrated into the molecular skeleton of carcinogenic compounds. For every carcinogenic molecule that contains at least one atom of an element that appears in no other molecule in the database, I want the number of bonds its atoms of that element take part in....
'+' is the label of a carcinogenic molecule, '-' of a non-carcinogenic one; a bond is a link between two atoms of a molecule.
WITH rare AS (SELECT element FROM atom GROUP BY element HAVING COUNT(DISTINCT molecule_id) = 1) SELECT m.molecule_id, COUNT(DISTINCT c.bond_id) AS bond_count FROM molecule AS m INNER JOIN atom AS a ON a.molecule_id = m.molecule_id LEFT JOIN connected AS c ON (c.atom_id = a.atom_id OR c.atom_id2 = a.atom_id) WHERE m.lab...
challenging
491
toxicology
I'd like a ranked inventory of every molecule in the toxicology database that contains at least one carbon atom. For each qualifying molecule, give me its molecule id, carcinogenicity label, number of atoms, number of bonds, number of carbon atoms, number of chlorine atoms, number of carbon-touching bonds, and number o...
A carbon-touching bond is a bond with a carbon atom at one of its ends; a bond between two carbon atoms counts as one bond. A multiple bond is a double or triple bond. The carcinogenicity label '+' means carcinogenic, '-' means not carcinogenic.
WITH CarbonBonds AS (SELECT a.molecule_id, COUNT(DISTINCT c.bond_id) AS carbon_bond_count FROM connected c JOIN atom a ON c.atom_id = a.atom_id WHERE a.element = 'c' GROUP BY a.molecule_id), MoleculeStats AS (SELECT m.molecule_id, m.label, (SELECT COUNT(*) FROM atom a WHERE a.molecule_id = m.molecule_id) AS atom_count,...
challenging
492
toxicology
I'm studying the hydrogen bonding pattern of the molecule that contains the yttrium atom. How many bonds in that molecule have a hydrogen atom at one end? Just give me the single overall count, please.
An yttrium atom has element symbol Y; a hydrogen atom has element symbol H.
SELECT COUNT(DISTINCT c.bond_id) AS bond_count FROM connected AS c JOIN atom AS a ON a.atom_id = c.atom_id OR a.atom_id = c.atom_id2 WHERE a.element = 'h' AND a.molecule_id = (SELECT molecule_id FROM atom WHERE element = 'y')
challenging
493
toxicology
As part of a connectivity review, I'd like to know how heavily atoms are connected in molecule TR397: what is the average number of bonds an atom of TR397 has? Please give me just that one number, rounded to two decimal places.
SELECT ROUND(AVG(cnt), 2) AS avg_bonds_per_atom FROM (SELECT a.atom_id, COUNT(DISTINCT c.bond_id) AS cnt FROM atom a LEFT JOIN connected c ON (c.atom_id = a.atom_id OR c.atom_id2 = a.atom_id) WHERE a.molecule_id = 'TR397' GROUP BY a.atom_id)
challenging
494
toxicology
I'm studying bond patterns in compounds that are not carcinogenic. For each element, how many double or triple bonds join a carbon atom to an atom of that element, across all non-carcinogenic molecules? Give me one row per element with the element and its count of such bonds—nothing else.
A molecule labeled '-' is not carcinogenic; a molecule labeled '+' is carcinogenic.
SELECT a2.element AS element, COUNT(DISTINCT c.bond_id) AS bond_count FROM connected c JOIN bond b ON c.bond_id = b.bond_id JOIN atom a1 ON c.atom_id = a1.atom_id JOIN atom a2 ON c.atom_id2 = a2.atom_id JOIN molecule m ON b.molecule_id = m.molecule_id WHERE m.label = '-' AND a1.element = 'c' AND b.bond_type != '-' GROU...
challenging
495
toxicology
For molecule TR377, I'd like a profile of its bond composition, covering single and double bonds only. For each bond kind, please give me: the bond kind symbol, the number of bonds of that kind in the molecule, and the number of element pairs that bond kind joins. Also include the molecule's carcinogenicity label. List...
A single bond is shown as the symbol '-' and a double bond as '='; a molecule label '+' means carcinogenic and '-' means not carcinogenic.
WITH scoped AS ( SELECT bond_type, COUNT(*) AS bond_count FROM bond WHERE molecule_id = 'TR377' AND bond_type IN ('-', '=') GROUP BY bond_type ), pairs AS ( SELECT b.bond_type, COUNT(DISTINCT CASE WHEN a1.element < a2.element THEN a1.element || '-' || a2.element ELSE a2.element || '-' || a1.element END) AS pair_count F...
challenging
496
toxicology
I'm screening for molecules to flag for follow-up. Can you give me the molecule_id of the first three molecules, in alphabetical order, that are non-carcinogenic, contain at least one metal atom, and have single bonds between their atoms? Please return only the molecule ids.
A molecule label of '-' means the molecule is non-carcinogenic. A bond type of '-' means a single bond between two atoms. The metals are sodium (na), potassium (k), calcium (ca), copper (cu), zinc (zn), tin (sn), lead (pb), magnesium (mg) and lithium (li).
SELECT DISTINCT T1.molecule_id FROM molecule AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN atom AS T3 ON T1.molecule_id = T3.molecule_id WHERE T2.bond_type = '-' AND T1.label = '-' AND T3.element IN ('na','k','ca','cu','zn','sn','pb','mg','li') ORDER BY T1.molecule_id LIMIT 3
challenging
497
toxicology
I'm profiling the compound library and want to size the fully saturated portion of each element's atom population - atoms attached only by single bonds behave differently from unsaturated sites. For each element symbol in the database, how many atoms are connected only by single bonds and never part of any multiple bon...
A single bond is a bond between two atoms sharing exactly one electron pair, denoted by the bond-type symbol '-'. A multiple bond is a double or triple bond, i.e. a bond between two atoms sharing more than one electron pair.
WITH per_atom AS (SELECT a.atom_id AS atom_id, a.element AS element, CASE WHEN EXISTS (SELECT 1 FROM connected AS c WHERE c.atom_id = a.atom_id) AND NOT EXISTS (SELECT 1 FROM connected AS c JOIN bond AS b ON b.bond_id = c.bond_id WHERE c.atom_id = a.atom_id AND b.bond_type <> '-') THEN 1 ELSE 0 END AS saturated FROM at...
challenging
498
toxicology
In the toxicology compound database, which elements take part in a triple bond, and how widely are they distributed across the tested compounds? For each such element, give me its element symbol and the number of molecules that contain that element. Order the results from the most widespread element to the least; where...
The '#' bond-type symbol denotes a triple bond.
SELECT a.element AS element, COUNT(DISTINCT a.molecule_id) AS n_molecules FROM atom AS a WHERE a.element IN (SELECT at.element FROM bond AS b JOIN connected AS c ON b.bond_id = c.bond_id JOIN atom AS at ON c.atom_id = at.atom_id WHERE b.bond_type = '#') GROUP BY a.element ORDER BY n_molecules DESC, a.element
challenging
499
toxicology
For molecule TR397, I want to see which elements form the bonding skeleton. For each element present among its atoms, how many atoms of that element take part in at least one bond? Please report two things per row: the element symbol (e.g. c, h, o) and the number of that element's atoms in TR397 that take part in a bon...
Takes part in a bond: the atom is one of the two atoms a bond joins.
SELECT a.element, COUNT(DISTINCT CASE WHEN c.bond_id IS NOT NULL THEN a.atom_id END) AS bonded_atoms FROM atom a LEFT JOIN connected c ON (c.atom_id = a.atom_id OR c.atom_id2 = a.atom_id) WHERE a.molecule_id = 'TR397' GROUP BY a.element ORDER BY a.element
challenging