在两个字段上加入两个表

时间:2016-03-04 13:54:18

标签: postgresql

我正在使用Postgresql并尝试在两个字段上连接两个表:

SELECT a.high, a.low, a.stname, a.zipcode, b.bhs, b.street_numb, b.street, b.address, b.zipcode
FROM bin a
JOIN zp b
ON (a.stname = b.street) and (a.low = b.street_numb);

但是,我收到以下错误:

ERROR:  operator does not exist: character varying = integer
LINE 4: on (a.stname = b.street) and (a.low = b.street_numb);
                                        ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

我如何才能获得正确的结果?

2 个答案:

答案 0 :(得分:0)

您要求Postgres比较两种不同类型,characterinteger。如果您确定a.low是数字,

CAST (a.low AS INT) = b.street_numb

答案 1 :(得分:0)

ALTER TABLE zp ALTER COLUMN street_numb TYPE character(5);