返回多个子子查询错误

时间:2017-05-10 09:30:56

标签: mysql

数据库记录在事务上花费的行动和时间。 这些操作记录在表格中,其中时间在“howlong”字段中以小数形式记录,并且每小时费用存储在字段“费用”中。它们通过matterid链接到事务表。当一组行动被计费时,“开帐单”字段显示为“Y”

我有一个页面正在从包括上表的多个表格中生成报告。它工作正常,直到我尝试添加所有这些行为的费用总和*费用,当我得到'子查询返回超过1行'时,billed ='N'。

我为了获得总数(这是给出错误的代码)而添加的代码是:

(Select ROUND((SUM(howlong*matterjuncactions.fee)),2)
                   FROM matterjuncactions JOIN matters ON 
matters.matterid=matterjuncactions.matterid
                  WHERE matterjuncactions.billed='N' GROUP BY matters.matterid) AS nonbillsum

整个查询是:

SELECT `ref`, nickname, type, statusnsteps, finalemail, bible, (matterjuncoriginals.sent) AS origsent, GROUP_CONCAT(DISTINCT staff.initials SEPARATOR '; ') AS lds, CONCAT(DATE_FORMAT(matterjuncupdate.updatedate,'%D %M %Y'),' - ',matterjuncupdate.who) AS uptext, (Select GROUP_CONCAT(distinct initials SEPARATOR ', ')
                   from matterjuncstaff INNER join staff on staff.staffid = matterjuncstaff.staffid
                  where matterjuncstaff.lead = 'N' AND matterjuncstaff.matterid = matters.matterid) AS otstf, 
(Select ROUND((SUM(howlong*matterjuncactions.fee)),2)
                   FROM matterjuncactions JOIN matters ON matters.matterid=matterjuncactions.matterid
                  WHERE matterjuncactions.billed='N' GROUP BY matters.matterid) AS nonbillsum
FROM matters 
LEFT JOIN matterjuncstaff ON matterjuncstaff.matterid = matters.matterid AND lead = 'Y'
LEFT JOIN staff on matterjuncstaff.staffid=staff.staffid
LEFT JOIN matterjuncupdate ON matters.matterid=matterjuncupdate.matterid
LEFT JOIN matterjuncoriginals ON matters.mattercode=matterjuncoriginals.mattercode
LEFT JOIN matterjuncactions ON matters.mattercode=matterjuncactions.mattercode
WHERE `state` = 'Open' AND type='1'
GROUP BY matters.matterid
ORDER BY nickname ASC

我已经查看了“子查询返回超过1行”错误的一些答案但是他们没有帮助我。我接受我的代码不是最好的,但任何帮助解决这个问题都将非常感激。

0 个答案:

没有答案