SELECT CUST_ID, AGE_NAME FROM PM_AGET_INFO START WITH CUST_ID in (SELECT CUST_ID FROM p_act_allow_manager WHERE ACTIVITY_ID = '425') CONNECT BY PRIOR CUST_ID = FATH_CUST_ID 如何将上述返回重复行去除?
时间: 2024-02-10 16:10:40 浏览: 157
mysql SELECT语句去除某个字段的重复信息
5星 · 资源好评率100%
您可以使用 Oracle 中的 DISTINCT 关键字来去除重复行,示例如下:
```
SELECT DISTINCT
CUST_ID,
AGE_NAME
FROM
PM_AGET_INFO
START WITH
CUST_ID IN (
SELECT CUST_ID
FROM p_act_allow_manager
WHERE ACTIVITY_ID = '425'
)
CONNECT BY
PRIOR CUST_ID = FATH_CUST_ID;
```
另外,如果您想要在去重的同时保留某些字段的重复值,可以使用 GROUP BY 子句来实现。例如,如果您想要按照 CUST_ID 分组并计算每个分组中的行数,可以使用以下查询语句:
```
SELECT
CUST_ID,
AGE_NAME,
COUNT(*) AS ROW_COUNT
FROM
PM_AGET_INFO
WHERE
CUST_ID IN (
SELECT CUST_ID
FROM p_act_allow_manager
WHERE ACTIVITY_ID = '425'
)
GROUP BY
CUST_ID,
AGE_NAME;
```
阅读全文