sql - MySQL - Trying to show results for rows that have 0 records...across 3 columns -
there's lot of q&a out there how make mysql show results rows have 0 records, involve 1-2 tables/fields @ most.
i'm trying achieve same ends, across 3 fields, , can't seem it.
here's i've hacked together:
select circuit.circuit_name, county.county_name, result.adr_result, count( result.adr_result ) num_results ( select cases.case_id, cases.county_id, cases.result_id cases cases.status_id <> "2" ) q1 right join county on q1.county_id = county.county_id right join circuit on county.circuit_id = circuit.circuit_id right join result on q1.result_id = result.result_id group adr_result, circuit_name, county_name order circuit_name, county_name, adr_result
what need see list of circuits in first column, list of counties per circuit in second column, list of possible adr_result entries each county (they're same every county) in third column, , respective count circuit/county/result combination-- if 0. i've tried every combination of left, right , inner join (i know inner not solution, i'm frustrated) , can't see i'm going wrong.
any appreciated!
here start. can't follow problem statement completely. instance, purposes of cases table? none less, when "all" records each of tables, interpret cartesian product - implemented through derived table in clause (notice lack of join in clause)
select everthingjoin.circuit_name , everthingjoin.county_name , everthingjoin.adr_result , count(result.adr_result) num_results (select circuit.circuit_name, county.county_name, result.adr_result, circuit join county join result) everthingjoin left join cases on cases.status_id <> "2" , cases.county_id = everthingjoin.county_id left join circuit on everthingjoin.circuit_id = circuit.circuit_id left join result on cases.result_id = result.result_id group adr_result, circuit_name, county_name order circuit_name, county_name, adr_result
Comments
Post a Comment