0

我是 mysql 和 php 的新手,在进行复杂查询方面还没有那么经验丰富。感谢stackoverflow上的一些用户,下面的查询现已成功运行。我现在缺少的最后一点是在此查询中包括计算 q1 的总成本和 q2 的成本之间的差异。提前感谢您的帮助。干杯

Select * from ( SELECT invoice.eventid, invoice.invoiceno, event.clientid, client.clientid, clientname, 
gross_amount, vat, total, due 
FROM client, invoice, event 
WHERE event.eventid = invoice.eventid 
AND event.clientid = client.clientid) 
as q1

inner JOIN (SELECT event_ma.eventid, 
salary.staffid, Sum(cost_hour * Time_to_sec(Timediff(hours, pause))) / 3600 AS costs 
FROM salary 
JOIN event_ma ON salary.staffid = event_ma.staffid GROUP BY event_ma.eventid) 
as q2  
ON q1.eventid = q2.eventid 

GROUP BY q1.eventid
4

1 回答 1

0

在您的主要语句中添加计算字段SELECT

Select *, (q1.total - q2.costs) AS difference
from ( SELECT invoice.eventid, invoice.invoiceno, event.clientid, client.clientid, clientname, 
gross_amount, vat, total, due 
FROM client, invoice, event 
WHERE event.eventid = invoice.eventid 
AND event.clientid = client.clientid) 
as q1

inner JOIN (SELECT event_ma.eventid, 
salary.staffid, Sum(cost_hour * Time_to_sec(Timediff(hours, pause))) / 3600 AS costs 
FROM salary 
JOIN event_ma ON salary.staffid = event_ma.staffid GROUP BY event_ma.eventid) 
as q2  
ON q1.eventid = q2.eventid 

GROUP BY q1.eventid
于 2013-04-28T07:17:41.033 回答