Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Luuk
On 18-2-2019 14:51, Simon Slavin wrote: On 18 Feb 2019, at 1:33pm, Rocky Ji wrote: Here's the new thing: https://pastebin.com/raw/pSqjvJdZ Again, can we get rid of them sub-query? The "sum()" with the "group by" in the subquery make it difficult. There's nothing wrong with that query just

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Keith Medcalf
create table coaches ( coachID integer primary key autoincrement, coach_name text ); create table players ( playerID integer primary key autoincrement, playerName text not null, salary integer, fk_coach integer, constraint abc foreign key

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Keith Medcalf
On Monday, 18 February, 2019 02:27, Rocky Ji : >Awesome, thanks for the detailed analysis; this is why I love mailing >lists. >It seems you jumped to the meat directly, in the opening of my >question, >notice the words "scenario" and "given". >I am sure you know what they mean, but for record:

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Simon Slavin
On 18 Feb 2019, at 1:33pm, Rocky Ji wrote: > Here's the new thing: https://pastebin.com/raw/pSqjvJdZ > > Again, can we get rid of them sub-query? The "sum()" with the "group by" in the subquery make it difficult. There's nothing wrong with that query just as it is. In that form SQLite will

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Rocky Ji
Whoa! Big revelation. I didn't know foreign keys were disabled by default. And my code just ran in sqlite3 shell, and this made me think text and rowid and etc foreign keys "just worked". Sorry for the ruckus. Here's the new thing: https://pastebin.com/raw/pSqjvJdZ Again, can we get rid of them

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread R Smith
On 2019/02/18 11:24 AM, Clemens Ladisch wrote: Rocky Ji wrote: But everyone advices against nested select statements. Who? I've heard rumors that older version of the Oracle query optimizer did worse with subqueries than with joins, but such advice is not necessarily correct for SQLite. +1

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Rocky Ji
Awesome, thanks for the detailed analysis; this is why I love mailing lists. It seems you jumped to the meat directly, in the opening of my question, notice the words "scenario" and "given". I am sure you know what they mean, but for record: the links I gave help in "reproducing the problem" in a

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-18 Thread Clemens Ladisch
Rocky Ji wrote: > But everyone advices against nested select statements. Who? I've heard rumors that older version of the Oracle query optimizer did worse with subqueries than with joins, but such advice is not necessarily correct for SQLite. SQL is set-based language, and queries that are

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-17 Thread Keith Medcalf
create table coaches (coach_name text); create table players ( playerName text not null, salary integer, fk_coach text, constraint abc foreign key (fk_coach) references coaches (coach_name) ); create table matches ( playedAgainst text not null,

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-17 Thread Rocky Ji
@Keith Thanks. I am new to SQL and DB in general; please clarify what *is it valid* means. How do I check validity of schema? On Mon, Feb 18, 2019, 1:17 AM Keith Medcalf > Nice schema. Do you have a valid one? > > > --- > The fact that there's a Highway to Hell but only a Stairway to Heaven

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-17 Thread Rocky Ji
@Luuk that was my initial approach. But everyone advices against nested select statements. Can we do it without that sub-query? On Sun, Feb 17, 2019, 11:04 PM Luuk > On 17-2-2019 17:46, Rocky Ji wrote: > > Hello everyone, > > > > How can I prevent group by clause from reducing the number of

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-17 Thread Keith Medcalf
Nice schema. Do you have a valid one? --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-Original Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Rocky Ji >Sent:

Re: [sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-17 Thread Luuk
On 17-2-2019 17:46, Rocky Ji wrote: Hello everyone, How can I prevent group by clause from reducing the number of rows without affecting accuracy of what aggregate functions provide? Scenario: My club has-many coaches. Each coach trains a team of players. Of course, a player has-many matches

[sqlite] How to get aggregate without reducing number of rows (repeats are ok)?

2019-02-17 Thread Rocky Ji
Hello everyone, How can I prevent group by clause from reducing the number of rows without affecting accuracy of what aggregate functions provide? Scenario: My club has-many coaches. Each coach trains a team of players. Of course, a player has-many matches and a match has-many players. Given the