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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dailyjournal.gitbook.io/solutions/hackerrank-solutions/prepare/sql/advanced-select.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
