PostgreSQL中的DISTINCT WHERE查询 [英] DISTINCT WHERE query in PostgreSQL
本文介绍了PostgreSQL中的DISTINCT WHERE查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在postgresql中的一个选择的不同查询中放置where子句,但是没有运气。
I'm trying to put a where clause in a select distinct query in postgresql but having no luck.
我想执行以下操作:
select distinct on (state_or_county) state_or_county
from locations
where country = "USA"
我已经在mysql中做过很多次了,不明白为什么它不起作用。
I've done this many times in mysql and can't understand why this isn't working.
有人可以更正查询吗?还是解释一下为什么它不起作用?
Can someone please correct the query? Or explain just why it isn't working?
推荐答案
在PostgreSQL中,字符串文字必须用单引号引起来:
In postgresql a string literal must be wrapped in single quotes:
select distinct on (state_or_county) state_or_county
from locations
where country = 'USA'
如有必要,双引号用于标识符:
Double quotes are used for identifiers, if needed:
select distinct on ("state_or_county") "state_or_county"
from "locations"
where "country" = 'USA'
这篇关于PostgreSQL中的DISTINCT WHERE查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文