Solutions
HackerRank
HackerRank
  • Home
  • 👨🏻‍💻 Profile
  • Prepare
    • Linux Shell
      • Bash
    • Python
      • Introduction
    • SQL
      • Basic Select
      • Advanced Select
      • Aggregation
      • Basic Join
  • Tutorials
    • 10 Days of Javascript
      • Day 0
      • Day 1
      • Day 2
      • Day 3
  • Certify
    • C# (Basic)
    • JavaScript (Basic)
    • SQL (Basic)
    • Rest API (Intermediate)
Powered by GitBook
On this page
  • Type of Triangle
  • The PADS
  • Occupations
  • Binary Tree Nodes
  • New Companies

Was this helpful?

  1. Prepare
  2. SQL

Advanced Select

PreviousBasic SelectNextAggregation

Last updated 2 years ago

Was this helpful?

Type of Triangle

select 
    case 
        when A >= (B + C) or B >= (A + C) or C >= (A + B) then 'Not A Triangle'
        when A <> B and B <> C and A <> C then 'Scalene'
        when A = B and B = C and A = C then 'Equilateral'
        when A = B or B = C or A = C then 'Isosceles'
    end
from TRIANGLES;

The PADS

select Name || '(' || substr(Occupation,1,1) || ')'  
from OCCUPATIONS
order by Name;

select 'There are a total of ' || count(Occupation) || ' ' || lower(Occupation) || 's.' 
from OCCUPATIONS
group by Occupation
order by count(Occupation), Occupation;

Occupations

// Some code

Binary Tree Nodes

select N,
    case 
        when P is null then 'Root'
        when N in (select P from BST) then 'Inner'
        else 'Leaf'
    end 
from BST
order by N;

New Companies

select 
    C.company_code, C.founder, 
    count(distinct E.lead_manager_code), 
    count(distinct E.senior_manager_code), 
    count(distinct E.manager_code),
    count(distinct E.employee_code)
from company C, employee E
where C.company_code = E.company_code
group by C.company_code, C.founder
order by 1;
LogoType of Triangle | HackerRankHackerRank
LogoThe PADS | HackerRankHackerRank
LogoOccupations | HackerRankHackerRank
LogoBinary Tree Nodes | HackerRankHackerRank
LogoNew Companies | HackerRankHackerRank