简体   繁体   中英

SQL sub-query: select all values but for one type of values only higher than

Is it possible to get all values for all currencies but for one particular currency only those that are higher than let's say 10000 USD?

select case
    when currency_id = '57' then 'EUR'
    when currency_id = '26' then 'USD'
    when currency_id = '51' then 'HKD' end as CCY,
    amount, ECPNBR, value_date
    from money_transfer
    where (select amount from money_transfer where currency_id ='26')>10000 order by amount desc;

this gets error that "subquery returns more than 1 value..."

maybe put your query like below

select 
 case
  when m.currency_id = '57' then 'EUR'
  when m.currency_id = '26' then 'USD'
  when m.currency_id = '51' then 'HKD'
  else '' 
 end,
 m.amount, m.ECPNBR, m.value_date
from money_transfer  where ( m.currency_id='26' and m.amount>10000) OR (m.currency_id<>'26')
order by m.amount desc;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM