bulding cte to aggregate different columns and using pivot

fk_inprocess 1 Reputation point
2020-10-30T21:18:53.447+00:00

Hi All,
Need some help/feedback on best way to approach this table:
I'm trying to show a company with 1 client

And for that clients how many solo interviews were conducted on their behalf

And for those that required group_interviews : group_interviews >0

How many people they interviewed weren’t coming from (IBM,Hubspot,salesforce, sisens) column is null

How many who had a group interviewed came from IBM,Hubspot,salesforce, sisens) columns in not null
Here is the table

date userid solo_interview group_interview Hubspot salesforce IBM tableau sisens round_trip one way trip clients_size
5/7/2020 KKLOP35 2 null null null null 4 null null null 1
6/9/2020 54PTLCT 4 null null 2 null null null 1 3 1
10/2/2020 OPKQ33 0 45 8 2 null 3 null null 20 15
3/9/2018 494KOP6 5 null null null null 5 null 1 null 1
1/4/2020 4324RED 4 3 4 6 null null null 3 null 1
3/8/2020 UYH 8 null 5 null 75 null 1 2 null 2
6/15/2020 1062JKY 1 null 85 null 3 10 1 35 null 51
2/1/2020 FGU6LLD 1 null 3 null null null 21 null 3 5
6/4/2019 2360TYU 0 2 null 3 null null 5 2 4 3

So the diagram will look like this

              1 seat
          |               |

solo interview grouped interviews
| |
interviewed:hubspot, IBM, didn't interviewed any tech prospect
Salesforce, sisen

This is what I have thus far, but im stuck to pull other info:

one_clients as ( SELECT date
,user_id
,sum(no_group_meeting) as solo
FROM table
WHERE clients_size = 1
AND group_interview is null
GROUP By 1,2
)
select * from one_seats_no_group

I would love the table to look at this

Client_size solo_interview group_interview_non_tech group_interview(tech:IBM,Salesforce,hubspot)
1 23 17 182
2-29 165

thank you

Azure Database for PostgreSQL
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,656 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.