2017-07-07 57 views
-3

这是我的查询的文本,有一个语法错误。查询的语法有什么问题?

select cc, sum(a.hours),b.labcost 
from labour a,othshop b 
where lab_cd='hs' and a.mon=03 and a.yr=2010 
group by a.cc 
HAVING a.cc=b.occ AND b.mon=03 and b.yr=2010; 

所有的表格都存在。这个查询的文字有什么问题?

+0

欢迎来到SO。请参考[tour](https://stackoverflow.com/tour),阅读[如何提问](https://stackoverflow.com/questions/how-to-ask),并编辑您的问题以包含[最小,完整和可验证示例](https://stackoverflow.com/help/mcve)。 – jeff6times7

回答

0

没有必要在having,只是:

select a.cc, sum(a.hours),b.labcost 
from labour a,othshop b 
where lab_cd='hs' and a.mon=03 and a.yr=2010 
and a.cc=b.occ AND b.mon=03 and b.yr=2010 
group by a.cc, b.labcost 

注意b.labcost添加到GROUP BY。否则,您需要对其执行汇总,例如avg(b.labcost)

+0

谢谢。但我只需要通过a.cc进行分组此程序是在DBASE系统中创建的,我试图将其转换为基于mysql和php的数据库。 –

+0

然后按照我的建议 - 尝试找出如何将多个“b.labcost”转换为每个“a.cc”单行。明显的候选人是“avg”,“sum”或“coalesce” – Dimgold