1

我的子查询返回不止一行,我需要第一行并保留我的 max 函数

Select ...
Where GHTY_FIRME.FIRME_ID= (Select   FIRME_ID
                           FROM imag_verification_tube 
                           WHERE (numero_dossier =  '12004' OR NUMERO_TIRE= '12004')
                           AND CREE_LE = (select max (CREE_LE) 
                           from tableX where(numero_dossier ='12004' OR 
                           NUMERO_PQDCS= '12004 ')));
4

1 回答 1

1

使用rownum伪列:

Select ...
Where GHTY_FIRME.FIRME_ID= (Select   FIRME_ID
                           FROM imag_verification_tube 
                           WHERE (numero_dossier =  '12004' OR NUMERO_TIRE= '12004')
                           AND CREE_LE = (select max (CREE_LE) 
                                          from tableX 
                                          where(numero_dossier ='12004' 
                                               OR NUMERO_PQDCS= '12004 ') 
                                               and rownum < 2));

另请参阅关于 ROWNUM 和限制结果

也就是说,您可以尝试优化 sql。我要做的第一件事就是将内部 SQL 转换为连接。此外,根据您的业务逻辑,也可以消除 or条件

于 2013-01-10T20:06:59.373 回答