0

postgresqlのselectdistinctクエリにwhere句を入れようとしていますが、うまくいきません。

私は次のことをしたい:

select distinct on (state_or_county) state_or_county 
from locations 
where country = "USA"

私はこれをmysqlで何度も実行しましたが、なぜこれが機能しないのか理解できません。

誰かがクエリを修正できますか?または、それが機能しない理由を説明してください。

4

1 に答える 1

2

postgresql では、文字列リテラルは一重引用符で囲む必要があります。

select distinct on (state_or_county) state_or_county 
from locations 
where country = 'USA'

必要に応じて、識別子には二重引用符が使用されます。

select distinct on ("state_or_county") "state_or_county" 
from "locations" 
where "country" = 'USA'
于 2012-09-18T15:30:00.843 に答える