database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
ㆍSybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Sybase Q&A 2099 게시물 읽기
No. 2099
쿼리 분석좀 해주세요...^^;;
작성자
천적
작성일
2007-11-23 09:41
조회수
7,103

Sybase 12.5를 사용하고 있습니다.


select count(1) from aaa where 2 between "20070401" and "20070930"

--> 94건 발생

select count(1) from aaa where 2 between "20070401" and "20070930"

and not exists(select 1 from b b where 1 = b.1 and 2 = b.2 and 3 = b.3 )

--> 0건 발생

select count(1) from aaa where 2 between "20070401" and "20070930"

and exists(select 1 from bbb b where b.1 = 1 and b.2 = 2 and b.3 = 3 )

--> 94건 발생

select count(1) from aaa a where a.2between "20070401" and "20070930"

and not exists(select 1 from bbb b where a.1= b.1 and a.2= b.2 and a.3 = b.3)

--> 83건 발생


이런 쿼리가 있습니다. 보시면 아시지만 aaa a를 해서 not exists에서 넣어서 사용하면 제대로 건수를 먹습니다.

하지만 aaa 로 alias를 안주고 쿼리를 날려보면 건수를 못가져 오고 exists로 바꾸면 모든 건수를 가져오고 있습니다.


두개의 쿼리가 다른건가요??


내부적으로 어떻게 돌아가길래 이런 건수의 오류(?)가 나오는걸까요??


또 제가 원하는건 저 83건을 삭제하고 싶은겁니다. 94건이 아니고요..

그래서 이렇게 쿼리를 날리면

delete aaa a where a.2between "20070401" and "20070930"

and not exists(select 1 from bbb b where a.1= b.1 and a.2= b.2 and a.3 = b.3)


Server Message:  Number  102, Severity  15

Server 'ccocs', Line 1:

Incorrect syntax near 'a'. 


이런 에러가 발생하네요...^^;; 고수분들의 고견좀 부탁드립니다...


수고하세요...

이 글에 대한 댓글이 총 2건 있습니다.

null column이 있는지 확인하세요 null 컬럼이 있다면
isnull로 변경해야됨

create table #temp( c char(1) null, d char(1) null)
insert #temp values ('1', null)
insert #temp values ('2', null)

create table #temp2( c char(1) null, d char(1) null)
insert #temp2 values ('1', null)

select count(1) from #temp a where exists (select 1 from #temp2 b where a.c = b.c and a.d = b.d)
 0건
select count(1) from #temp a where not exists (select 1 from #temp2 b where a.c = b.c and a.d = b.d)
 
 2건

delete시 from절을 사용하세요

delete aaa a where a.2 between "20070401" and "20070930"
and not exists(select 1 from bbb b where a.1= b.1 and a.2= b.2 and a.3 = b.3)
==>
delete aaa from aaa a where where a.2 between "20070401" and "20070930"
and not exists(select 1 from bbb b where a.1= b.1 and a.2= b.2 and a.3 = b.3)




영빈~(backfish)님이 2007-11-25 15:33에 작성한 댓글입니다.
이 댓글은 2007-11-25 15:35에 마지막으로 수정되었습니다.

답변 정말로 감사합니다.

from절을 사용하라는 고견은 정말 감사합니다.

그런대 조인키에 null값이 있는지 보라고 하신문제는 그 1, 2, 3이라는 키가 unique이면서 
기본키입니다.
aaa, bbb 테이블 모두 마찬가지입니다.

그래서 null값은 절대 있을수 없습니다.

다시 한번 고견 부탁드립니다.

천적님이 2007-11-26 14:26에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
2102특정월의 일자수와 요일수 구하는법 조언부탁드립니다. [1]
질문자
2007-11-23
6662
2101이런 조회 조건은 어떻게 하면 구현할수 있을까요? [2]
이승현
2007-11-23
7005
2100질문하나 더 드립니다..^^;;
천적
2007-11-23
6445
2099쿼리 분석좀 해주세요...^^;; [2]
천적
2007-11-23
7103
2098ODBC 접속 에러입니다.
박효진
2007-11-21
6963
2096bcp in 할때 텍스내용에 사이즈 제한이? [2]
궁금이
2007-11-20
6822
2095이런 결과가 가능한가요? [2]
웹드래곤
2007-11-20
6386
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다