当我运行此查询时,我得到多个具有相同地址的家庭成员,我只想要每个家庭/地址一行。
SELECT distinct last_name, first_name, address_1, city, state_code, zip_code
from guest
WHERE address_1 IS NOT NULL
GROUP by last_name, first_name, address_1, city, state_code, zip_code
答案 0 :(得分:2)
如果您希望每个系列/地址占一行,只需从查询中删除第一个名称,如下所示:
SELECT last_name, address_1, city, state_code, zip_code
from guest
WHERE address_1 IS NOT NULL
GROUP by last_name, address_1, city, state_code, zip_code;
我也放弃了DISTINCT
,因为你有GROUP BY
,所以没有必要。
希望有所帮助。