Oracle sql group by then sort -
i'm trying split query results 2 groups, ones have flag of y , ones have flag n. need sort groups based on 2 things.
here's query i've tried doesn't work group bit:
select location, country web_loc_info flag = 'y' or flag = 'n' , available_online = 'y' group flag order country, location_desc
any great in advance replies
it might worth clarifying "group" in oracle (from group by
operation) 1 or more rows of raw data has been consolidated single row in result.
recall that:
select flag web_loc_info group flag order flag
is equivalent to
select distinct flag web_log_info order flag
(if flag column contains y , n values, both queries return 2 rows.)
so, in future, when think "group" ask if mean "summarize data there's 1 row each group value" (in case "y"/"n" values in flag column) in case group by
clause you're after or if want put sort rows same values in case you're looking @ order by
.
i'd randy , harshit above pretty close i'd include flag column in select list can see "group" location , country values belong (and making obvious break in grouping occurs):
select flag, location, country web_loc_info flag in ('y', 'n') , available_online = 'y' order flag, -- desc if want y rows show first location, -- desc? or there column called location_desc? country
Comments
Post a Comment