Re: [sqlite] How to group this?

2020-02-11 Thread Bart Smissaert
Solved this now, nil to do with SQL, but just running a different search (other value code and then you can ask for a secondary value and no need anymore to find the matching pair). RBS On Mon, Feb 10, 2020 at 8:22 AM Bart Smissaert wrote: > I fully agree with you, but I sofar I have no

Re: [sqlite] How to group this?

2020-02-11 Thread Jean-Luc Hainaut
On 11/02/2020 01:35, Simon Slavin wrote: I don't think that creating an index on a view actually works, does it? You're right. What was I thinking ? Maybe I've used another implementation of SQL that it does work on. Thanks for picking me up on it. You are right, SQL Server allows you to

Re: [sqlite] How to group this?

2020-02-10 Thread Simon Slavin
On 10 Feb 2020, at 10:41pm, Wolfgang Enzinger wrote: > Am Mon, 10 Feb 2020 01:42:14 + schrieb Simon Slavin: > >> On 10 Feb 2020, at 1:25am, no...@null.net wrote: >> >> create two VIEWs, [...]. Index both VIEWs on (id, date), > > I don't think that creating an index on a view actually

Re: [sqlite] How to group this?

2020-02-10 Thread Wolfgang Enzinger
Am Mon, 10 Feb 2020 01:42:14 + schrieb Simon Slavin: > On 10 Feb 2020, at 1:25am, no...@null.net wrote: > > create two VIEWs, [...]. Index both VIEWs on (id, date), I don't think that creating an index on a view actually works, does it? Wolfgang

Re: [sqlite] How to group this?

2020-02-10 Thread Jen Pollock
Sorry, I made a typo. The windows should be ORDER BY ROWID, not ORDER BY ID. Jen On Mon, Feb 10, 2020 at 09:19:59AM -0700, Jen Pollock wrote: > I think the following works: > > SELECT s.ID 'ID', s.Date Date, Systolic, Diastolic > FROM > (SELECT ID, ENTRY_DATE Date, NUMERIC_VALUE Systolic,

Re: [sqlite] How to group this?

2020-02-10 Thread Jen Pollock
I think the following works: SELECT s.ID 'ID', s.Date Date, Systolic, Diastolic FROM (SELECT ID, ENTRY_DATE Date, NUMERIC_VALUE Systolic, row_number() OVER id_date r FROM pressure WHERE TERM = 'Systolic' WINDOW id_date AS (PARTITION BY ID, ENTRY_DATE ORDER BY ID) ) s JOIN (SELECT ID,

Re: [sqlite] How to group this?

2020-02-10 Thread Richard Damon
On 2/9/20 11:44 PM, Rowan Worth wrote: On Mon, 10 Feb 2020 at 11:12, Richard Damon wrote: On 2/9/20 7:24 PM, Bart Smissaert wrote: ID ENTRY_DATE TERM NUMERIC_VALUE ROWID 1308 15/Mar/2013 Systolic 127 701559 1308 15/Mar/2013

Re: [sqlite] How to group this?

2020-02-10 Thread Bart Smissaert
I fully agree with you, but I sofar I have no control over this data, I have it like I showed. As far as I can see there always will be a secondary value, but as you say I can't be sure. All this has to do with changing our clinical coding system from Read codes to Snomed. In the old setup there

Re: [sqlite] How to group this?

2020-02-09 Thread Rowan Worth
On Mon, 10 Feb 2020 at 11:12, Richard Damon wrote: > On 2/9/20 7:24 PM, Bart Smissaert wrote: > > ID ENTRY_DATE TERM NUMERIC_VALUE ROWID > > > > 1308 15/Mar/2013 Systolic 127 701559 > > 1308 15/Mar/2013 Diastolic 81 701568 > > 1308

Re: [sqlite] How to group this?

2020-02-09 Thread Richard Damon
On 2/9/20 7:24 PM, Bart Smissaert wrote: ID ENTRY_DATE TERM NUMERIC_VALUE ROWID 1308 15/Mar/2013 Systolic 127 701559 1308 15/Mar/2013 Diastolic 81 701568 1308 27/Jun/2013 Systolic 132 701562 1308 27/Jun/2013 Systolic 141 701563

Re: [sqlite] How to group this?

2020-02-09 Thread Keith Medcalf
to Heaven says a lot about anticipated traffic volume. >-Original Message- >From: sqlite-users On >Behalf Of no...@null.net >Sent: Sunday, 9 February, 2020 18:26 >To: SQLite mailing list >Subject: Re: [sqlite] How to group this? > >On Mon Feb 10, 2020 at 12:24:33AM +00

Re: [sqlite] How to group this?

2020-02-09 Thread Keith Medcalf
. >-Original Message- >From: sqlite-users On >Behalf Of Keith Medcalf >Sent: Sunday, 9 February, 2020 19:17 >To: SQLite mailing list >Subject: Re: [sqlite] How to group this? > > select id, > entry_date, > max(case when term == 'Systolic'

Re: [sqlite] How to group this?

2020-02-09 Thread Keith Medcalf
select id, entry_date, max(case when term == 'Systolic' then reading end) as Systolic, max(case when term == 'Diastolic' then reading end) as Diastolic from the_table group by id, entry_date ; If you want to make sure you have both terms for a given

Re: [sqlite] How to group this?

2020-02-09 Thread Simon Slavin
On 10 Feb 2020, at 1:25am, no...@null.net wrote: > Here is one way that appears to generate the correct result. Another way: create two VIEWs, one for systolic, one for diasystolic. Index both VIEWs on (id, date), then JOIN ON id AND date. If you want to, you could use this to make a third

Re: [sqlite] How to group this?

2020-02-09 Thread nomad
On Mon Feb 10, 2020 at 12:24:33AM +, Bart Smissaert wrote: > I should get: > > 127/81 > 132/82 > 141/85 > 143/94 > > What should be the SQL to group like this? Here is one way that appears to generate the correct result. CREATE TABLE pressure( id INTEGER PRIMARY KEY,