Answer the question
In order to leave comments, you need to log in
Request to collect statistics from 3 tables
Good afternoon! I'll start right away, there is a table with a description of the DATA data
ID | NAME | TypeID |
---|---|---|
one | Brick | one |
2 | Tile | one |
3 | Table | 2 |
ID | DATAID | DATE | USERID |
---|---|---|---|
one | one | 04.05.2012 | 2 |
2 | one | 04.05.2012 | 3 |
3 | 2 | 05.05.2012 | 4 |
ID | DATAID | DATE | Gues |
---|---|---|---|
one | one | 05/06/2012 | here cookies |
2 | one | 04.05.2012 | here cookies |
3 | 2 | 05.05.2012 | here cookies |
SELECT
DATE_FORMAT(StatUser.Date, '%d-%m-%Y') as Date,
COUNT(IF(Data.TypeID=1,1,NULL)) as TypeID1View,
COUNT(IF(Data.TypeID=2,1,NULL)) as TypeID2View
FROM
Data
INNER JOIN StatUser ON StatUser.DataID = Data.ID
WHERE
StatUser.Date > DATE_ADD(NOW(), INTERVAL -7 DAY)
GROUP BY Date
ORDER BY Date
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question