Answer the question
In order to leave comments, you need to log in
How to filter in the first table based on the data in the third (through the second)?
There are three tables:
Table1 (ID, Title)
Table2 (ID, Title, Table1.ID)
Table3 (ID, Title, Quantity, Table2.ID)
The first table is related to the second: 1 to ∞
The second table is related to the third: 1 to ∞
There are two tasks:
1. Display one value: the number of rows in Table1 , where in Table3 the value of the Quantity field will be greater than zero.
2. Display a table with two columns:
a) Table1.Name
b) Sum of field values Table3.Quantity , which refer to each row of Table1 .
Answer the question
In order to leave comments, you need to log in
I came up with the solutions myself (although I'm not completely sure):
SELECT Таблица1.Название, SUM(Таблица3.Количество) as 'count'
FROM Таблица1, Таблица2, Таблица3
WHERE (Таблица3.Таблица2_ИД = Таблица2.ИД) AND
(Таблица2.Таблица1_ИД = Таблица1.ИД) AND
count > 0
GROUP BY Таблица1.ИД
SELECT Таблица1.Название, SUM(Таблица3.Количество)
FROM Таблица1, Таблица2, Таблица3
WHERE (Таблица3.Таблица2_ИД = Таблица2.ИД) AND
(Таблица2.Таблица1_ИД = Таблица1.ИД)
GROUP BY Таблица1.ИД
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question