Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL中的独特WHERE查询_Postgresql - Fatal编程技术网

PostgreSQL中的独特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

我试图在postgresql中的select distinct查询中放入where子句,但没有成功

我想做以下工作:

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规范方面倾向于偏离任务,这意味着它所做的事情与您可能期望的略有不同,并导致用户在切换到另一个遵循规则的数据库时养成坏习惯。