You are given a table transactions with:
id
(primary key)
amount_str
(VARCHAR): a numeric string representing an amount in dollars (e.g.,
'950'
,
'2500000'
,
'9876543210'
).
Task (SQL): Write a query that outputs id and a formatted amount string:
< 1,000,000
: output like
$950
(no suffix).
1,000,000 <= amount < 1,000,000,000
: output as dollars in millions with suffix
M
, rounded to
1 decimal
(e.g.,
2500000 -> $2.5M
).
>= 1,000,000,000
: output as dollars in billions with suffix
B
, rounded to
1 decimal
(e.g.,
9876543210 -> $9.9B
).
Assume amount_str may contain leading/trailing spaces; you should convert it to a numeric type before comparing/dividing.
Login required