试图找到交易金额<= $ 10的至少1项交易
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了试图找到交易金额<= $ 10的至少1项交易相关的知识,希望对你有一定的参考价值。
我试图找到不同交易的数量,数量的总和,dollar_value_us的总和以及至少一个Item> = $ 10值的distinct_id_id的数量。我创建了一个sql数据库。我也试图打破范围内的dollar_value_us
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=e1ee5e9a6264d758f4a7480fa8d6b964
样本数据:
individual_id | dollar_value_us | quantity | transaction_number | sku | txn_date | brand_org_code | is_merch | currency_code | line_item_amt_type_cd ------------: | --------------: | -------: | -----------------: | :----- | :------------------ | :------------- | -------: | :------------ | :-------------------- 1 | 10 | 30 | 567 | 903633 | 02/01/2019 00:00:00 | BRAND | 1 | USD | S 1 | 20 | 30 | 567 | 123767 | 02/01/2019 00:00:00 | BRAND | 1 | USD | S 2 | 11 | 80 | 910 | 363635 | 02/11/2019 00:00:00 | BRAND | 1 | USD | S 3 | 9 | 62 | 855 | 678364 | 02/12/2019 00:00:00 | BRAND | 1 | USD | S
答案
使用聚合:
select Dollar_Range, count(distinct individual_id), count(*), sum(quantity)
from (select t.*,
(case when dollar_value_us < 10 then 'below $10'
when dollar_value_us < 20 then '$10 - $20'
when dollar_value_us < 30 then '$20 - $30'
when dollar_value_us < 40 then '$30 - $40'
when dollar_value_us < 50 then '$40 - $50'
else '$50 - above'
end) as dollar_range
from t
) t
group by dollar_range
order by min(dollar_value_us);
另一答案
select 'below $10' as Dollar_Range count(individual_id), count(transaction_number), sum(quantity) from myData where dollar_value_us < 10
union
select '$10 - $20' as Dollar_Range count(individual_id), count(transaction_number), sum(quantity) from myData where dollar_value_us >=10 and dollar_value_us < 20
union
select '$20 - $30' as Dollar_Range count(individual_id), count(transaction_number), sum(quantity) from myData where dollar_value_us >=20 and dollar_value_us < 30
union
select '$30 - $40' as Dollar_Range count(individual_id), count(transaction_number), sum(quantity) from myData where dollar_value_us >=30 and dollar_value_us < 40
union
select '$40 - $50' as Dollar_Range count(individual_id), count(transaction_number), sum(quantity) from myData where dollar_value_us >= 40 and dollar_value_us < 50
union
select '$50 - above' as Dollar_Range count(individual_id), count(transaction_number), sum(quantity) from myData where dollar_value_us >50
以上是关于试图找到交易金额<= $ 10的至少1项交易的主要内容,如果未能解决你的问题,请参考以下文章
Paypal Express Checkout 在许多交易中捕获大量金额(大于 10.000 美元)