-3

Here is the text of my query that has a syntax error.

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;

All the tables exist. What is wrong with the text of this query?

Jeff Holt
  • 2,940
  • 3
  • 22
  • 29
  • Welcome to SO. Please take the [tour](https://stackoverflow.com/tour), read [How to Ask](https://stackoverflow.com/questions/how-to-ask), and edit your question to include a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Jeff Holt Jul 07 '17 at 16:35

1 Answers1

0

There is no need in having, just:

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

note that b.labcost was added to the GROUP BY. Otherwise, you'll need to perform an aggregation on it, such as avg(b.labcost)

Dimgold
  • 2,748
  • 5
  • 26
  • 49
  • Thanks. but i need to group only by a.cc This program was made in a DBASE system I am trying to convert it into a mysql and php based database. – Rahul Pramanik Jul 07 '17 at 17:33
  • then as I suggested- try to figure out how to convert multiple ``b.labcost`` into a single line per ``a.cc``. The obvious candidates are ``avg``, ``sum`` or ``coalesce`` – Dimgold Jul 07 '17 at 17:35