testing - Two questions about SQL based on an ERD diagram. (novice level) -


i've attached picture shows erd diagram these 2 questions apply to.

the erd optometry doctors , patients. it's coursework i'm having trouble understanding these two.

any sql savvy people out there willing me out corresponding sql statements? thank you. this erd

1. list of patient’s name , doctor treats patient, date of last eyetype result, last glasses type , brand, show these patients live either chicago or san diego. order date , inside on patient’s name

  1. a list shows per each brand of glasses total count of every patient wears corresponding brand. show results total amount of patients more 25.

your sql query start, there few things aware of:

  1. how tables related? how can join them in query (how connect?)?

  2. in select statement, think it's asking 'glass type' rather 'eye type'

  3. select statement missing from, indicating tables you're selecting - add joins need make relate tables

  4. where clause looks good

  5. order missing date (though 'date' isn't specified - start date or end date?)

anyway, putting gets this:

select name_patient, name_doctor, type, brand, start_date, end_date patients inner join doctors on patients.patientnumber = doctors.patientnumber inner join type_of_glasses on patients.patientnumber = type_of_glasses.patientnumber city = 'chicago' or 'san diego' order start_date, end_date, name_patient; 

now you're ready try number 2. think 'count' goes 'group by' , condition 'having > 25' , not 'where'

edited:

really close on 2. need add join condition (on ...) , edit count in select line wrap field in parentheses. group tells query groups you're counting, here you're grouping brand , counting how many patients have brand.

select count(name_patient), brand  patients inner join type_of_glasses  on patients.patientnumber = type_of_glasses.patientnumber group brand having count(name_patient) > 25 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -