Skip to content

Instantly share code, notes, and snippets.

@toke
Last active May 12, 2020 14:18
Show Gist options
  • Save toke/516e85185d961352aa2c2f7b3e2faaca to your computer and use it in GitHub Desktop.
Save toke/516e85185d961352aa2c2f7b3e2faaca to your computer and use it in GitHub Desktop.

Kleiner Test mit Sqlite

Sqlite-Datenbank öffnen

sqlite3 test.sqlite3

Testtabelle tbl1 erzeugen:

create table tbl1 (probe int, parameter int, result Char(10))

Mit Daten füllen:

insert into tbl1 VALUES (12, 9, null);
insert into tbl1 VALUES (12, 9, "AGAG");
…
select * from tbl1;
1|2|abc
1|3|
2|1|def
2|3|def
2|9|
1|9|
12|9|
12|9|AGAG

Und nun der eigentliche Query:

SELECT DISTINCT a.probe, a.parameter, COALESCE(b.result, a.result)
    FROM tbl1 AS a
    LEFT OUTER JOIN tbl1 b
      ON a.probe = b.probe
    WHERE b.result NOT NULL;
    
1|2|abc
1|3|abc
1|9|abc
2|1|def
2|3|def
2|9|def
12|9|AGAG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment