Skip to content
Advertisement

How to print the required output with the help of SQL

I have tables ‘users’ and ‘user_transactions’ in AWS Athena. The table has many columns but I am interested in 2 columns viz. user name and txn_type.

The txn_type column has 3 possible values viz. FT, NFT, PT.

For each user, I need to print the count of each transactions in the below format. The output should contain 4 columns with userId, and count of each txns.

Morover, I need to join user and user_transactions table for printing records of users who are of type = ‘Gold’

so to find the users, it will be

Then for these users, I need to print the output with 4 columns as described above.

So if a user with name = ‘ABC’ and Id = 1 and user_type = ‘Gold’ has 3 counts of FT, 5 counts of NFT and 0 counts of PT,

and if a user with name = ‘XYZ’ and Id = 2 and user_type = ‘Gold’ has 9 counts of FT, 0 counts of NFT and 45 counts of PT, the output should be the output should be

How can I write a query which can print all counts in a single row?

Advertisement

Answer

You can calculate each field individually like so:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement