Android Question Help with SQL - query

moster67

Expert
Licensed User
Longtime User
Don't know if it is possible but if it is, how can I using SQL get a query result as in this layout:

Person Client 2016Client 2017Supplier 2016Supplier 2017
Mr. GreenUSD 500USD 300USD 200USD 400


from a table (let us say an Invoice table) as follows (of course it could be an csv-file):
Mr GreenClient, year 2016USD 500
Mr GreenClient, year 2017USD 300

Mr Green
Supplier, year 2016USD 200
Mr Green,Supplier, year 2017USD 400

It's late and I am stuck but perhaps someone can give me a helping hand.

Probably involves grouping..

Thanks.
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
It would be cool is ChatGPT could provide the answer to this!
 
Upvote 0

LGS

Member
Licensed User
Longtime User
Try this:

1671512575844.png


select distinct i1.person, i2.amount Client2016, i3.amount Client2017,i4.amount Supplier2016, i5.amount Supplier2017
from invoice i1
full join invoice i2 on i2.person = i1.person and i2.year = 'Client, year 2016'
full join invoice i3 on i3.person = i1.person and i3.year = 'Client, year 2017'
full join invoice i4 on i4.person = i1.person and i4.year = 'Supplier, year 2016'
full join invoice i5 on replace(i5.person,',','') = i1.person and i5.year = 'Supplier, year 2017'
where i1.person = 'Mr Green'

1671513028234.png
 
Upvote 0
Top