SQL - 避免重复列

时间:2014-12-07 14:47:02

标签: sql oracle oracle-apex

这是我的代码,我想在它们完全相同的地方只显示一次A.SITES_CODE和A.SITES_NAME。这是我的代码,我尝试了HAVING功能,但它不符合我的标准。

SELECT     A.SITES_CODE, A.SITES_NAME, D.DESCRIPTION
FROM       ZZZ_SITES_AVAILABLE A, ZZZ_DIFFICULTY_RATINGS D, ZZZ_SITES_VISITED V, ZZZ_HOLIDAY_DETAILS H
WHERE      A.SITES_CODE = V.SITES_CODE
AND        V.CODE_OF_HOLIDAY = H.CODE_OF_HOLIDAY
AND        H.DIFFICULTY_RATING = D.HOLIDAY_DIFFICULTY
AND        LENGTH(D.DESCRIPTION) > 6
GROUP BY   A.SITES_CODE, A.SITES_NAME, D.DESCRIPTION
HAVING     COUNT(*) >= 1
ORDER BY   A.SITES_CODE;

The table is showing this result:

1 个答案:

答案 0 :(得分:0)

您需要从description中删除group by。在此过程中,您还应学习使用正确的ANSI标准JOIN语法:

SELECT A.SITES_CODE, A.SITES_NAME
FROM ZZZ_SITES_AVAILABLE A JOIN
     ZZZ_SITES_VISITED V
     ON A.SITES_CODE = V.SITES_CODE JOIN
     ZZZ_HOLIDAY_DETAILS H
     ON V.CODE_OF_HOLIDAY = H.CODE_OF_HOLIDAY JOIN
     ZZZ_DIFFICULTY_RATINGS D
     ON H.DIFFICULTY_RATING = D.HOLIDAY_DIFFICULTY
WHERE    LENGTH(D.DESCRIPTION) > 6
GROUP BY   A.SITES_CODE, A.SITES_NAME
HAVING     COUNT(*) >= 1
ORDER BY   A.SITES_CODE;