jeudi 5 mai 2016

Perform JOIN in SQLITE on two SELECT statements from the same table

This is how I have a sample table in SQLITE

ID  NAME    AGE ADDRESS     SALARY
1   Paul    32  California  20000.0
2   Allen   25  Texas   15000.0
3   Teddy   23  Norway  20000.0
4   Mark    25  Rich-Mond   65000.0
5   David   27  Texas   85000.0
6   Kim 22  South-Hall  45000.0
7   Paul    32  California  20000.0
8   Allen   25  Texas   15000.0
9   Teddy   23  Norway  20000.0

What I want to achieve is a join on my SQLITE table on these two queries

select AGE, count(*)  as SALARYLESSTHAN45 from company where salary < 45000 group by salary 

select AGE, count(*)  as SALARYMORETHAN45 from company where salary > 45000 group by salary 

I tried the following

select AGE, count(*)  as SALARYLESSTHAN45 from company where salary < 45000 group by salary  ) T1
INNER JOIN
select AGE, count(*)  as SALARYMORETHAN45 from company where salary > 45000 group by salary  ) T2
ON T1.AGE = T2.AGE

but cannot get this to work...

Can someone share an example of how to achieve this in SQLITE ?

Aucun commentaire:

Enregistrer un commentaire