Real Time SQL Interview Queries|| Technical Round || PART-1

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 5

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 Місяць тому

    -- find gender percentage
    select
    Gender, CAST(ROUND(CAST(COUNT(*) as float)/CAST((select COUNT(*) from GenderData) as float) * 100, 2) as varchar)+'%' as GenderPercent
    from GenderData
    group by Gender
    --
    select
    Gender,
    SUM(CASE WHEN Gender = 'Male' THEN 1 ELSE 0 END) as MaleCount,
    SUM(CASE WHEN Gender = 'Female'THEN 1 ELSE 0 END) as FemaleCount
    from GenderData
    group by Gender;

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 Місяць тому

    proportion %
    select
    Name,
    CAST(CAST(CAST(SUM(Prize) as decimal)/CAST((select SUM(Prize) from ProportionData) as decimal) * 100 as decimal(10, 2)) as varchar) +'%' as Proportion_Percent
    from ProportionData
    group by Name

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 Місяць тому

    select
    Name,
    CAST(CAST(CAST(SUM(Prize) as decimal)/CAST((select SUM(Prize) from ProportionData) as decimal) * 100 as decimal(10, 2)) as varchar) +'%' as Proportion_Percent
    from ProportionData
    group by Name
    --
    ;with cte_temp as
    (
    select
    Name,
    Prize,
    SUM(Prize) OVER (ORDER BY Name ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as total
    from ProportionData
    )
    select Name, CAST(ROUND(cast(Prize as float)/cast(total as float) * 100, 2) as varchar)+'%' as proportion from cte_temp

  • @PavaniReddy-m2q
    @PavaniReddy-m2q 2 місяці тому +1

    please share the DDL and DML scripts also