Question

Disease Afflicts post sev pre sev --〈Takes Patient Drus SSN dosage duration

Write SQL queries to retrieve the requested information from the Drug Test database

(a) Find the names and ids of all patients who are afflicted with both depression and asthma.

(b) Find the names and ids of all patients who were completely cured by the end of their drug trial (as indicated by all post-treatment severity levels being 0).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solutions:

here SQL tables are as follows :

1) Patient Table

Field patientName patientId SSN Type varchar (30) NULL varchar (30) NULL varchar (30) NULL

patientName patientId SSN □ XYZ 7 2 RAM *(NULL,) (NULL) (NULL)

2) Disease Table

Field PatientId DiseaseName Diseaseld Type varchar (30) NULL varchar (30) NULL varchar (30) NULL

DỊPatientId Diseasellame Disease!a depression1 asthma asthma 2 NULL) NULL)

3) Drug Table

Field DrugId DrugName PatientId Duration Type varchar (30) NULL varchar (30) NULL varchar (30) NULL int (10) NULL

DrugId DrugName PatientId Duration *「(NULL) |(NULL) (NULL) NULL)

a) Find the names and ids of all patients who are afflicted with both depression and asthma.

Query :

SELECT DISTINCT patient.patientName, patient.patientId
FROM patient INNER JOIN Disease
ON patient.patientId = Disease.PatientId AND Disease.DiseaseName IN ('depression' ,'asthma')

SELECT DISTINCT patient.patientName, patient.patientId FROM patient INNER JOIN Disease ON patient .patientId Disease. Patient

Result :

  1 Result 2 Profiler 3 Messages 4 Table Data5 Info l patientName patientId

B) Find the names and ids of all patients who were completely cured by the end of their drug trial

Query :

SELECT DISTINCT patient.patientName, patient.patientId

FROM patient INNER JOIN Drug

ON patient.patientId = Drug.PatientId AND Drug.duration = 0

SELECT DISTINCT patient, patientName, patient.patientId FROM patient INNER JOIN Drug ON patient, patientId = Drug. PatientId  

Result :

  1 Result 3 Mes 2 Profiler ▼ | patientName patientId ▼|乓鹵 (Read Only) □XYZ

Add a comment
Know the answer?
Add Answer to:
Write SQL queries to retrieve the requested information from the Drug Test database (a) Find the names and ids of all patients who are afflicted with both depression and asthma. (b) Find the names an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION: (Answer in SQL) Write an SQL query to find all pairs of users (A,B) such...

    QUESTION: (Answer in SQL) Write an SQL query to find all pairs of users (A,B) such that both A and B have blurted on a common topic but A is not following B. Your query should print the names of A and B in that order. BACKGROUND INFO: Users can post their thoughts in form of short messages that we call “blurts”. When signing up, users need to provide their email and a password of their choice. In addition, they...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT