如何选择付款金额独特的客户

时间:2019-05-16 06:59:00

标签: mysql sql

如何选择付款金额(以UAH为单位)在150至400 UAH之间的唯一客户?

我有桌子:

•出生日期-交易日期;

•Transum数字(20,2)-付款金额;

•CurrencyRate数字(20.2)-货币汇率;

ID_Client Trandate  Transum CurrencyRate    Currency
1   2018.12.01  100 1   UAH
1   2018.12.02  150 2   USD
2   2018.12.01  200 1   UAH
3   2018.12.01  250 3   EUR
3   2018.12.02  300 1   UAH
3   2018.12.03  350 2   USD
7   2019.01.08  600 1   UAH

我的代码太糟糕了

SELECT DISTINCT ID_Client
,      Transum 
FROM   `Payment.TotalPayments` 
WHERE  Currency = "UAH" 
       AND Transum >= "150" 
       AND Transum <= "400"

一定是这样的:

SELECT ID_Client, COUNT(Transum)
FROM `Payment.TotalPayments`
HAVING COUNT(Transum) BETWEEN 150 AND 400

1 个答案:

答案 0 :(得分:0)

您可以在下面尝试-

export default 
  connect(
    mapStateToProps,
    mapDispatchToProps, null, {forwardRef: true})(Component)