:) I have 2 queries, and I need to join them, I need to compare the working time of employee depending on activity with total working time of company in the same activity in def
The simplest would be using sub-queries (though they're in general not too efficient, but those GROUP BY
's may make other solutions difficult).
Something like this should do it:
SELECT a.*, b.tottime AS 'Total time (company)'
FROM
(SELECT u.login, a.article, p.p_article, (SUM(p.p_going) + SUM(p.p_leaving) + SUM(p.p_working)) AS 'Total time (worker)'
FROM pos p, users u, articles a
WHERE u.login = p.p_login
AND REPLACE( u.login, '.', '_' ) = 'users_name'
AND p.p_datum >= '2013-04-09'
AND p.p_datum <= '2013-04-16'
AND p.p_article = a.id
GROUP BY a.article) a
LEFT JOIN
(SELECT a.article, p.p_article, (SUM(p.p_going) + SUM(p.p_leaving) + SUM(p.p_working)) AS tottime
FROM pos p, articles a
WHERE p.p_datum >= '2013-04-09'
AND p.p_datum <= '2013-04-16'
AND p.p_article = a.id
GROUP BY a.article) b
ON a.article = b.article /* AND a.p_article = b.p_article ?? */