-1
select CURRENCY.currencyname, currency.currencysymbol, COUNTRYNAME.currencycode, 
       currency.exchangerate
from CURRENCY,COUNTRYNAME
where currency.currencycode=COUNTRYNAME.currencycode
having currency.exchangerate >= max(currency.exchangerate)
group by CURRENCY.currencyname, currency.currencysymbol, 
         COUNTRYNAME.currencycode, currency.exchangerate;

这是我得到的输出,我知道这是错误的,因为我试图只显示最大汇率。因此,任何解决此查询的帮助将不胜感激。我是 oracle sql 开发者

CURRENCYNAME         CURRENCYSYMBOL       CURRENCYCODE EXCHANGERATE
-------------------- -------------------- ------------ ------------
British Pound        £                    GBP                     1,
US Dollar            $                    USD                1.9626 ,
Danish Krone         kr                   DKK                9.9918 ,
Malaysian Ringgit    RM                   MYR               6.35392 ,
Euro                 €                    EUR               1.34076 ,
Indian Rupee         Rs                   INR               77.3265 ,
Japanese Yen         ¥                    JPY               209.881, 
4

3 回答 3

0

尝试以下

SELECT CURRENCY.currencyname, currency.currencysymbol, 
       COUNTRYNAME.currencycode, MAX(currency.exchangerate) as ExchangeRate
FROM CURRENCY
INNER JOIN COUNTRYNAME ON COUNTRYNAME.currencycode = currency.currencycode
GROUP BY CURRENCY.currencyname, currency.currencysymbol, COUNTRYNAME.currencycode;
于 2013-04-20T11:15:13.313 回答
0

此查询可能可以简化为:

select max(currencyname), max(currencysymbol), currencycode, max(exchangerate)
from currency group by currencycode

(-假设没有任何国家从未使用过的货币。)

于 2013-04-20T11:21:54.827 回答
0

关于您的查询...

1. 您无法将 MAX(聚合)值与同一查询级别内的基值进行比较。您可以使用派生表(又名“子查询”),例如

    选择 c.currencyname、c.currencysymbol、n.currencycode、c.exchangerate
    从货币 c
    在 c.currencycode=n.currencycode 上加入 COUNTRYNAME n
    其中 c.exchangerate = (select max(exchangerate) from currency)

2. 您会从上面注意到我使用 JOIN 来链接两个表。大约 21 年前,随着 ANSI-92 连接语法的出现,使用逗号列表的表名已经过时了。

3. 如图所示,您的查询无法正常工作。GROUP BY子句属于子句之前,而HAVING不是之后。话虽如此,上述第一点适用,无论如何您都无法将 MAX 值与(基)列值进行比较。

于 2013-04-20T11:19:42.817 回答