E
E
enchikiben2012-06-09 13:37:53
MySQL
enchikiben, 2012-06-09 13:37:53

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

and two statistics tables for registered users (StatUser)
ID DATAID DATE USERID
one one 04.05.2012 2
2 one 04.05.2012 3
3 2 05.05.2012 4

and for guests (StatGues)
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


It is necessary to write a query that displays the number of visited data by day for different types of accounts and with the ability to summarize data from both statistics tables. I was only able to do from one table:

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


Here it is necessary to somehow include a table with guests ... Help :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeek, 2012-06-09
@EnChikiben

UNION is right for you? :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question