count - nested sql queries with case statement -


I am trying to use the results of a subquery as a derived table for the external query, since then Calculates and gives information to the group. Subkey This is a section of my SQL, and despite seeing me several examples online, luck does not get the right of syntax.

This subkey is:

  select rname.rn_country as country, in the form of rname.rn_index id, yoga (rresults.rr_sec_total) time-rname intermediate rresults rresults When joining rname.rn_index = rresults.rr_rn_index where rn_view = 'right' and rr_date = '6/6 / 2012' and (rr_slide = 'standard' or rr_slide = 'water') group by rn_index, rn_country sum (rresults .rr_sec_total) & gt; = 18000   

This is the result of:

I need to do the ID where (what time and gt is counting the number; = 18000 and time = 36000) bronze, (time> = 36000 And & lt; = 54000) is silver, and time & gt; More than 54000 gold is classified by country. Therefore, based on the results of the above values, the end result will be:

CAN: 1 gold
DEN: 1 bronze
United States: 3 gold 1 silver

Looking at, what should the whole query do? Thanks in advance. Any help appreciated.

Why not count individual columns such as:

  select Do a.country, COUNT (case when a.time> 54000 then 1 end) num_gold, count of (case when a.time between 36000 and 54000 then 1 end) num_silver, COUNT (as the case when A. 18000 and 36000 then 1 end) time between num_bronze (country, as rname.rn_index id, rname rr.n_index = rresults at rname from yoga (select rname.rn_country as rresults.rr_sec_total). Rr_rn_index Where rresults as the time of joining the rresults form _view = 'right' and 'rr_date =' 6/6/2012 'and (rr_slide =' standard 'or' rr_slide = 'water' ') by rn_index group, rn_country amount (rresults.rr_sec_total)>, by = 18000 by one) Group Country    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -