Yes you can use, multiple ways you can solve the problem .
@duraiprabhu433711 күн бұрын
select state,city,min(population),max(population) from city_info group by (State,City);
@codinglake11 күн бұрын
Nice one.
@sushmitasaha90833 күн бұрын
this approach will give state twice and not distinguish between max and min and will display max value under both the columns (same for min)
@KRANTHIKUMARMARADA6 күн бұрын
with cte as (select c.*, row_number() over (partition by state order by population) minpop , row_number() over (partition by state order by population desc) maxpop from city_info c) select state, min(case when minpop=1 then city end) minpopulation, min(case when maxpop=1 then city end) maxpopulation from cte group by state
@suhastl308722 күн бұрын
Didnt get the max(case condition) and min(case condition) how did it eliminate null
@madarasi36021 күн бұрын
Group function is eliminated the null value
@codinglake21 күн бұрын
watch full video then you understand the logic. Don't skip video.
@NikhilKumar-of5ek15 күн бұрын
@@madarasi360 group by is a clause not a function.
@sachinn55032 күн бұрын
WITH CTE AS( SELECT *, ROW_NUMBER() OVER(PARTITION BY STATE ORDER BY POPULATION ASC) RANK_LOW, ROW_NUMBER() OVER(PARTITION BY STATE ORDER BY POPULATION DESC) RANK_HIGH FROM CITY_INFO) SELECT STATE,CITY,POPULATION FROM CTE WHERE RANK_LOW=1 OR RANK_HIGH=1 ORDER BY STATE,CITY;
@codinglakeКүн бұрын
Nice 👍
@sreesailampavankalyan100716 күн бұрын
Select state, max(population) as max_population, min(population) as min_population from table Group by state