我目前对刚开始支持的应用程序中的模块有两个不同的查询(第一个编程工作)。第一个查询选择引擎所在的所有汽车 (9,10,11,12,13)。第二个获取引擎所在的所有汽车(4,44)。它们都工作正常,唯一的问题是当它们被放置在 JSP 上的同一个表中时,它们不使用相同的过滤器。所以基本上,第一个查询的所有数据总是排在第一位,第二个查询的数据总是排在第二位。如果按字母顺序排序,它将对第一个查询 AZ 中的所有数据进行排序,然后对第二个查询 AZ 中的数据进行排序,因此您会看到如下内容:
A Car with Engine 11
B Car with Engine 9
C Car with Engine 13
D Car with Engine 12
A Car with Engine 44
B Car with Engine 44
C Car with Engine 4
所以我认为最好只做某种 CASE 和 JOIN 组合并且只有一个查询。不幸的是,我很难找出最好的方法来做到这一点。数据是从 Oracle 数据库中的视图中提取的。以下是两个查询:
SELECT DISTINCT
P.CAR_ID CAR_ID,
P.TYPE TYPE,
P.LAST_TIME_SERVICED LAST_TIME_SERVICED,
P.SERVICE_TYPE SERVICE_TYPE,
P.PURCHASE_DATE PURCHASE_DATE,
'20'|| SUBSTR (P.MODEL_YEAR, 1, 2)|| ' - '|| '20'|| SUBSTR (P.MODEL_YEAR, 3, 4) MODEL_YEAR,
P.DESCRIPTION DESCRIPTION,
P.ENGINE_TYPE ENGINE_TYPE,
V.MODEL_ID MODEL_ID,
V.POPULAR_NAME POPULAR_NAME,
V.GMC GMC,
V.DISPUTE DISPUTE,
V.ENGINE ENGINE,
'20'|| SUBSTR (V.YEAR, 1, 2)|| ' - '|| '20'|| SUBSTR (V.YEAR, 3, 4) YEAR,
DECODE (V.SUBS, '~', NULL, V.SUBS) SUBS,
V.CONSEC CONSEC,
RFI.CUST_CUST_ID CUST_CUST_ID,
RFI.SALESMAN SALESMAN
FROM DEALER.VW_INV_FOR_SALE RFI, DEALER.VW_OLD_SALES P,
DEALER.VW_NEW_SALES V
WHERE P.ENGINE_TYPE IN (9,10,11,12,13)
AND V.MODEL_ID = RFI.MODEL_ID
AND RFI.MODEL_ID = P.MODEL_ID
AND V.YEAR >='1011'
AND V.YEAR = P.MODEL_YEAR
AND V.ENGINE = P.ENGINE_TYPE
AND V.SUBS = P.SUBSCRIPT
AND P.DESCRIPTION != '100% SAFE'
AND RFI.CUST_CUST_ID IN (SELECT CUST_ID FROM CUSTOMERS WHERE CUST_ID = ?
UNION
SELECT CUST_ID FROM CUSTOMERS
START WITH CUST_CUST_ID = ?
CONNECT BY PRIOR CUST_ID = CUST_CUST_ID)
SELECT DISTINCT
P.CAR_ID CAR_ID,
P.TYPE TYPE,
P.LAST_TIME_SERVICED LAST_TIME_SERVICED,
P.SERVICE_TYPE SERVICE_TYPE,
P.PURCHASE_DATE PURCHASE_DATE,
'20'|| SUBSTR (P.MODEL_YEAR, 1, 2)|| ' - '|| '20'|| SUBSTR (P.MODEL_YEAR, 3, 4) MODEL_YEAR,
RFI.CUST_CUST_ID CUST_CUST_ID,
RFI.SALESMAN SALESMAN,
P.DESCRIPTION DESCRIPTION,
P.ENGINE_TYPE ENGINE_TYPE,
Q.MODEL_ID MODEL_ID,
Q.POPULAR_NAME POPULAR_NAME,
Q.GMC GMC,
Q.DISPUTE DISPUTE,
Q.ENGINE ENGINE,
'20'|| SUBSTR (Q.YEAR, 1, 2)|| ' - '|| '20'|| SUBSTR (Q.YEAR, 3, 4) YEAR,
DECODE (Q.SUBS, '~', NULL, Q.SUBS) SUBS,
Q.CONSEC CONSEC,
Q.RESULT RESULT
FROM DEALER.VW_INV_FOR_SALE RFI, DEALER.VW_OLD_SALES P,
DEALER.VW_ENGINE4_RESULT Q
WHERE P.ENGINE_TYPE IN (4,44)
AND Q.MODEL_ID = RFI.MODEL_ID
AND RFI.MODEL_ID = P.MODEL_ID
AND Q.YEAR >='1011'
AND Q.YEAR = P.MODEL_YEAR
AND Q.ENGINE = P.ENGINE_TYPE
AND Q.SUBS = P.SUBSCRIPT
AND P.DESCRIPTION != '100% SAFE'
AND RFI.CUST_CUST_ID IN (SELECT CUST_ID FROM CUSTOMERS WHERE CUST_ID = ?
UNION
SELECT CUST_ID FROM CUSTOMERS
START WITH CUST_CUST_ID = ?
CONNECT BY PRIOR CUST_ID = CUST_CUST_ID)
非常感谢您对此提供的任何帮助。