Question: Examine the following SQL query, and explain clearly and succinctly what it means. Will the query work? Explain why or why not WITH processed_users AS

Examine the following SQL query, and explain clearly and succinctly what it means. Will the query work? Explain why or why not

WITH processed_users AS (SELECT LEFT(u.phone_country, 2) AS short_phone_country,

u.id FROM users u)

SELECT t.user_id, t.merchant_country,

Sum(t.amount / fx.rate / Power(10, cd.exponent)) AS amount FROM transactions t

JOIN fx_rates fx ON ( fx.ccy = t.currency

AND fx.base_ccy = 'EUR' ) JOIN currency_details cd

ON cd.currency = t.currency JOIN processed_users pu

ON pu.id = t.user_id WHERE t.source = 'GAIA'

AND pu.short_phone_country = t.merchant_country GROUP BY t.user_id,

t.merchant_country ORDER BY amount DESC;

Here is the information you've asked for. I wasn't sure what format to give you this information in, since there's a lot of information.

I've asked our data engineer and he's provided some explanatory info below. Now I need to go! Let's catch up on Monday if you have any questions!

Best,

Rita Data Analyst

********** DATA EXPLANATION ***************

1. countries.csv - a table with all alpha-numeric representations of countries. You may need to use this to standardise country codes to one format 2. fx_rates.csv - a table with fx rates on a particular day 3. fraudsters.csv - this is list of IDs of users who have been identified as fraudsters but there's a bunch we haven't found yet! 4. train_transactions.csv - all transactions conducted by users - **amount** is denominated in integers at the lowest unit. e.g. 5000 GBP => 50 GBP (because the lowest unit in GBP is a penny, w/ 100 pence = 1 GBP) - **entry_method** is only relevant for card transactions (CARD_PAYMENT, ATM); you may ignore it for other transactions. The values are: misc - unknown chip - chip on card mags - magstripe on card manu - manual entry of card details cont - contactless/tap mcon - special case of magstripe & contactless - **source** is associated with an external party we use for handling this type of transaction. (e.g. all {CARD_PAYMENT, ATM} use GAIA) 5. train_users.csv - a table of user data - **kyc** column indicates the status of the user's identity verification process - **terms_version** column indicates the user's current version of the Revolut app 6. currency_details.csv - a table with iso codes and exponents for currencies - **exponent** column can be used to convert the integer amounts in the transactions table into cash amounts. (e.g for 5000 GBP, exponent = 2, so we apply: 5000/(10^2) = 50 GBP)

Tried to run it and it returns an empty table with free columns user_id, merchant_account, amount. Why this query returns an empty table?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!