hmmm, hat das einen Syntaxfehler? Ich seh ihn nicht.
Ankündigung
Einklappen
Keine Ankündigung bisher.
Minimum filtern
Einklappen
Neue Werbung 2019
Einklappen
X
-
Zitat von stackoverflow Beitrag anzeigenhmmm, hat das einen Syntaxfehler? Ich seh ihn nicht.Code:SELECT id, text_id, MIN(position) FROM texte WHERE text_id IN ($text_IDs_string) GROUP BY text_id
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Kommentar
-
Zuletzt geändert von stackoverflow; 23.07.2014, 23:15.Ich will ja eigentlich über id keine Gruppe (Aggregat) bilden und dachte, dieses id wirkt so, dass einfach jeweils die zu den Ergebnissen passenden id ausgegeben werden.
Wie sieht denn die richtige Syntax aus?
Kommentar
-
Zitat von stackoverflow Beitrag anzeigenIch will ja eigentlich über id keine Gruppe (Aggregat) bilden und dachte, dieses id wirkt so, dass einfach jeweils die zu den Ergebnissen passenden id ausgegeben werden.
Wie sieht denn die richtige Syntax aus?
Code:test=# select distinct on(text_id) id, text_id, position from stackoverflow order by text_id, position, id; id | text_id | position ----+---------+---------- 2 | 10 | 1 5 | 11 | 6 6 | 12 | 1 8 | 13 | 5 (4 rows)
Code:test=*# select id, text_id, min(position) from stackoverflow group by text_id order by position asc; ERROR: column "stackoverflow.id" must appear in the GROUP BY clause or be used in an aggregate function at character 8 STATEMENT: select id, text_id, min(position) from stackoverflow group by text_id order by position asc; ERROR: column "stackoverflow.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: select id, text_id, min(position) from stackoverflow group b... ^ test=*#
Code:test=*# select * from stackoverflow where (text_id, position) in (select text_id, min(position) from stackoverflow group by text_id) order by text_id; id | text_id | position ----+---------+---------- 2 | 10 | 1 5 | 11 | 6 6 | 12 | 1 8 | 13 | 5 (4 rows)
Code:test=*# select id, text_id, position from (select *, row_number() over (partition by text_id order by position) from stackoverflow ) foo where row_number = 1; id | text_id | position ----+---------+---------- 2 | 10 | 1 5 | 11 | 6 6 | 12 | 1 8 | 13 | 5 (4 rows)
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Kommentar
Kommentar