L
L
lukoie2021-09-21 23:49:52
SQLite
lukoie, 2021-09-21 23:49:52

How to correctly calculate the amounts for different tables?

correct amount

SELECT DISTINCT
  SUM("20.09".total)
FROM
  "20.09.2021" AS "20.09"

spoiler
614a4412be5da180236472.png

if you make two queries on two tables (for today and yesterday) - the amount will be different
SELECT DISTINCT
  SUM("20.09".total), 
  SUM("21.09".total)
FROM
  "20.09.2021" AS "20.09",
  "21.09.2021" AS "21.09"

spoiler
614a4420b2366352052199.png

it is necessary that it works like this, as for each record:
spoiler
614a44a21ec98059190080.png

why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-09-22
@Akina

This is the so-called join multiplying. To get the correct result, you must first aggregate, and only then link.
PS. DISTINCT in all queries is superfluous, because each of the queries is guaranteed to return only one record - well, what else is there to distinct?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question