:"NOT"コマンドのようなpostgres SQLにはコマンドがありますか?たとえば、
Apple is a and b
Banana is a and b
Orange is a
私はそれだけでだけではなくBで物事を表示するコマンドを記述しようとしています。
:"NOT"コマンドのようなpostgres SQLにはコマンドがありますか?たとえば、
Apple is a and b
Banana is a and b
Orange is a
私はそれだけでだけではなくBで物事を表示するコマンドを記述しようとしています。
今テーブル構造
Fruit | Attribute
Apple A
Apple B
Banana A
Banana B
Orange A
クエリ
select t1.* from tbl t1
where t1.attribute = 'A'
and not exists (select * from tbl t2
where t2.fruit=t1.fruit and t2.attribute <> 'A')
<>そのコマンドは何のために使われていますか? –
"does not equal" – RichardTheKiwi
単に 'SQL' タグ、これは標準SQL-2003です:
WITH tbl (Fruit, Attribute)
AS
(
SELECT Fruit, Attribute
FROM (
VALUES ('Apple', 'A'),
('Apple', 'B'),
('Banana', 'A'),
('Banana', 'B'),
('Orange', 'A')
) AS tbl (Fruit, Attribute)
)
SELECT T1.Fruit, T1.Attribute
FROM tbl AS T1
WHERE T1.Attribute = 'A'
AND 1 = (
SELECT COUNT(*)
FROM tbl AS T2
WHERE T2.Fruit = T1.Fruit
);
あなたは何を意味するのかexaclty?おそらく、あなたは 'LIKE'演算子を使いたいでしょう:http://www.postgresql.org/docs/9.0/interactive/functions-matching.html –