0
表のスキーマとデータをグローバルフィールドにする必要があります。psqlのクエリーカウントは条件
CREATE TABLE aaa (
nall integer NOT NULL,
ladata date NOT NULL,
txt text,
CONSTRAINT aaa_pkey PRIMARY KEY (nall, ladata)
)
データ:
2 | '2016-01-01' | 'a'
2 | '2016-02-02' | 'a'
5 | '2016-03-03' | 'a'
6 | '2016-03-03' | 'b'
問合せ:
select txt,
count(txt),
min(ladata),
(select count(txt) from aaa where txt !='')
from aaa
where ladata > (select MIN(ladata) from aaa) and nall != 2
group by txt
http://sqlfiddle.com/#!15/db06b1/1
返すために:
は私が TXT同じ を持つ行からの部分的数と2txt count min count b 1 March, 03 2016 00:00:00 1 a 3 March, 03 2016 00:00:00 3
からnallの異なると行から日付を必要とするが、テーブル全体からのカウントを返す保ちます:
txt count min count b 1 March, 03 2016 00:00:00 4 a 1 March, 03 2016 00:00:00 4
私はこれが解決策であるPostgreSQLの9.6
あなたの質問では、クエリやデータを含めます。 –
'where ladata>(aaaからのMIN(ladata)の選択)とnall!= 2'によると、クエリには2つのレコードを含める必要がありますか? – McNets