나는 확실히 당신이 게시하는지 신뢰하지 않는 ...
조회에 ORA-00979: Not a GROUP BY expression
가 발생한다. 이는 분석 함수에 포함되지 않은 열, 즉 username
이 group by
에 반영되지 않았기 때문입니다.
ORA-00920은 다음 중 하나가 누락되었음을 나타냅니다. =, <>, not in, in, !=, is not null, is null, not like, like
등 올바른 쿼리를 게시 했습니까? 과 같이, 테이블에 근접 뭔가 만들 11.2에서
:
create table host
( username varchar2(100)
, created_dt date);
insert into host
select level, sysdate - level
from dual
connect by level <= 10
;
insert into host
select chr(ascii(level) + 32), sysdate - level
from dual
connect by level <= 10
;
commit ;
을하고 쿼리를 실행은 ORA-00979에 결과를 기록했다. 이 변경 다음과 같은 작업의 미세 :
select case when regexp_like(username, '^\d+$') then 'GRP_OTHERS'
else username end as username
, count(*)
from host
where created_dt between
to_date('2012-may-23 00:00:00', 'yyyy-mon-dd hh24:mi:ss') and
to_date('2012-may-23 23:59:59', 'yyyy-mon-dd hh24:mi:ss')
group by case when regexp_like(username, '^\d+$') then 'GRP_OTHERS'
else username end
;
이 다른 방법으로 다시 쓸 수있다 :이 두 번째 쿼리가 더 당신이 원하는 것처럼 생각
select distinct username
, count(*) over (partition by case when regexp_like(username, '^\d+$')
then 'GRP_OTHERS'
else username end)
from host
where created_dt between
to_date('2012-may-23 00:00:00', 'yyyy-mon-dd hh24:mi:ss') and
to_date('2012-may-23 23:59:59', 'yyyy-mon-dd hh24:mi:ss')
. 실제 사용자 이름을 반환하지만 숫자 만있는 모든 그룹을 그룹화합니다. 대신 GRP_OTHERS
을 보려면 케이스가 반환 한 사용자 이름 열을 바꿉니다.
오라클의 경우 언어별로 일관성이있는 것은 아니기 때문에 필연적으로 오라클에서는 약간 더 좋습니다 (not to use the mon
format model). 대신 mm
을 사용하십시오.
9i를 사용하면서 대신 번역을 사용할 수 있습니다. 로 정규 표현식에 교체 :
trim(translate(username,'',' ')) is null
이 아무것도 번호를 대체하고 아무것도 왼쪽이 있는지 확인합니다 ... 당신이 여기서 뭘하려고 무엇
. 그룹 별 사례 –
사용자 이름 회의록을 하나의 그룹에두고 사용자 이름에 쉼표를 붙이시겠습니까? –
@ejb_guy 여기를 참조하십시오. http://stackoverflow.com/questions/10763043/sql-how-to-group-by-with-a-special-condition –