一家公司可以有一个或多个优惠 一个提议有很多工作
所以:公司< = offer< = numJobs
SELECT Count(t_offer.fkCompany) AS companies,
Count(t_offer.id) AS offers,
Sum(t_offer.nJobs) AS numJobs
FROM t_offer
例如:
idOFFER fkCOMPANY numJOBS
1 1 1
2 3 2
3 8 1
4 1 2
查询应为:
公司(3)< = offers(4)< = numJobs(6)
但结果是:
公司(4)< = offer(4)< = numJobs(6)
这是使用多个查询执行此操作的唯一方法吗?
答案 0 :(得分:1)
我认为你想要不同公司的数量?
SELECT Count(DISTINCT t_offer.fkCompany) AS companies,
Count(t_offer.id) AS offers,
Sum(t_offer.nJobs) AS numJobs
FROM t_offer