# Advanced Select

## Type of Triangle

{% embed url="<https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true>" %}

```sql
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

{% embed url="<https://www.hackerrank.com/challenges/the-pads/problem?isFullScreen=true>" %}

```sql
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

{% embed url="<https://www.hackerrank.com/challenges/occupations/problem?isFullScreen=true>" %}

```sql
// Some code
```

## Binary Tree Nodes

{% embed url="<https://www.hackerrank.com/challenges/binary-search-tree-1/problem?isFullScreen=true>" %}

```sql
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

{% embed url="<https://www.hackerrank.com/challenges/the-company/problem?isFullScreen=true>" %}

```sql
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;
```
