是否可以使用别名作为REGEXP_COUNT函数中的第一个参数,而不是实际的字段名称。例如,我使用了以下内容:
SELECT first_name ||' '|| last_name as fullname,
REGEXP_COUNT(fullname, 'o', 1, 'i') AS total
FROM BROKERS
我一直收到错误"无效的标识符"这让我觉得我必须把它称为一个字段而不是调用连接的"全名"
答案 0 :(得分:1)
如评论中所述,您需要使用子查询:
SELECT REGEXP_COUNT(b.fullname, 'o', 1, 'i') AS total
FROM (SELECT first_name ||' '|| last_name as fullname
FROM BROKERS) b;
或者你可以在函数中进行连接:
SELECT first_name ||' '|| last_name as fullname,
REGEXP_COUNT(first_name ||' '|| last_name, 'o', 1, 'i') AS total
FROM BROKERS
GROUP BY first_name ||' '|| last_name;
如果您想选择'全名'你需要的是group by
SELECT b.fullname,
REGEXP_COUNT(b.fullname, 'o', 1, 'i') AS total
FROM (SELECT first_name ||' '|| last_name as fullname
FROM BROKERS) b
GROUP BY b.fullname;