J
J
Justique2016-01-06 15:56:40
PHP
Justique, 2016-01-06 15:56:40

How to count the number of IDs by name and add the number to the result of another query?

Good afternoon,
There is a query that displays the number of clicks, form closes, unique visitors on my sites

SELECT site, year(date) as year, month(date) as month, day(date) as day, hour(date) as hour, SUM(w_init) as w_init, SUM(w_unique) as w_unique, SUM(w_close) as w_close FROM `f_click_log` where site='".$_val['name']."' AND date>='".$date_start." 00:00:00' AND date<='".$date_end." 23:59:59' GROUP BY year,month,site ORDER BY NULL

And there is a separate table in which there are orders from the form
SELECT count(id) as orders, year(date) as year, month(date) as month, day(date) as day, hour(date) as hour FROM f_orders WHERE client='{$_val['name']}' AND date>='".$date_start." 00:00:00' AND date<='".$date_end." 23:59:59' GROUP BY year,month

All data is grouped by year and month for the same period of time.
How to write the count from the second query to the results of the first query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
heartdevil, 2016-01-06
@heartdevil

Try this rubbish. Protest, esno, I can not. Therefore, in a general form, I give a request. To bring to mind.

SELECT fcl.site, year(fcl.date) as year, month(fcl.date) as month, day(fcl.date) as day, hour(fcl.date) as hour, COUNT(fo.id) AS orders, SUM(fcl.w_init) as w_init, SUM(fcl.w_unique) as w_unique, SUM(fcl.w_close) as w_close 
FROM `f_click_log` AS fcl
INNER JOIN `f_orders` AS fo ON fcl.site = fo.client  
WHERE fcl.site='".$_val['name']."' AND fcl.date>='".$date_start." 00:00:00' AND fcl.date<='".$date_end." 23:59:59' 
GROUP BY fcl.year, fcl.month, fcl.site

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question