PostgreSQL中的独特WHERE查询
我试图在postgresql中的select distinct查询中放入where子句,但没有成功 我想做以下工作:PostgreSQL中的独特WHERE查询,postgresql,Postgresql,我试图在postgresql中的select distinct查询中放入where子句,但没有成功 我想做以下工作: select distinct on (state_or_county) state_or_county from locations where country = "USA" 我在mysql中已经做过很多次了,但我不明白为什么这不起作用 有人能纠正这个问题吗?或者解释它为什么不工作?在postgresql中,字符串文字必须用单引号括起来: select distinct
select distinct on (state_or_county) state_or_county
from locations
where country = "USA"
我在mysql中已经做过很多次了,但我不明白为什么这不起作用
有人能纠正这个问题吗?或者解释它为什么不工作?在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'
请注意,SQL规范是这样说的。再一次,MySQL在SQL规范方面倾向于偏离任务,这意味着它所做的事情与您可能期望的略有不同,并导致用户在切换到另一个遵循规则的数据库时养成坏习惯。