잘못된 테이블을 검색 :중첩 SQL 쿼리 나는 두 개의 테이블이 (PostgreSQL을)
devices
(ID (INT), 유형 (INT))devices_log
(ID (INT), DEVICE_ID을 (INT) (FK), 데이터 (문자열) 타입은 1-10 사이의 수이다
날짜 (문자열))는, 상기 데이터 열은 1-100 ("1 사이의 수치 ", ...,"100 ") 또는 "em ptyX는 "(는 X는 어떠한 문자를 나타내는"는 Z ""을 ")
항상 9 타입을 갖는 데이터 열의 수를 갖는 장치.
I는 모두 "유형 9"에 대한 데이터 필드를 업데이트 는 데이터보다 큰 50되도록 ==> 데이터 = 데이터/2가 장치 할 필요가있다.
나는 INNER JOIN
시작했습니다
select l.id
from devices_log l
inner join (select id from devices where type = 9) d on (l.device_id = d.id)
where cast(data as INTEGER) > 50
내가 가진 :
이 문은 "유형 9"장치에 대한 모든 로그를 반환select l.id
from devices_log l
inner join (select id from devices where type = 9) d on (l.device_id = d.id)
,하지만 난 WHERE 조건을 추가 할 때 이 오류 :
ERROR: invalid input syntax for integer: "emptyG"
나는 같은 오류가 발생합니다.
select id
from devices_log
where device_id in (select id from devices where type = 9)
and cast(data as integer) > 50
select id from
(
select id, device_id, cast (devices_log.data as integer) as int_data
from devices_log
join devices on (devices_log.device_id = devices.id
) and type = 9) ccs where ccs.int_data > 50
의견이 있으십니까?
덕분에 사전에