我有两张table,一张table工作,一张table雇主。
我在计算每天每一份工作的就业人数。例如:
- job 1 has 5 new employee in day 2020-04-28 14:51:28.463
- job 2 has 3 employee in day 2020-04-28 18:11:23.111
- job 3 has 1 employee in day 2020-04-27 11:31:13.845
好吧,所以我应该有下一个信息:
Day 28: 8 employee
Day 27: 1 employee
我正在尝试这样做,但不起作用,因为它给了我双倍的回报,因为对于每个新员工,都会创建一个新行:
Select COUNT(convert(date, job.dateCreat ,103)) as jobsPerDay from jobTable job join jobEmpl jobEmp
on job.Id = jobEmp.Id
Group by convert(date, job.dateCreat ,103)
order by convert(date, job.dateCreat, 103) desc;
我没有使用子查询而不是联接,因为我需要更多的列来支持它。如果我使用它,则可以工作,但无法从第二个表中获取另一个列值:
Select COUNT(convert(date, job.dateCreat ,103)) as jobsPerDay from jobTable job join (Select distinct jobEmpl_id from jobEmp) as jobEmp
on job.Id = jobEmp.Id
Group by convert(date, job.dateCreat ,103)
order by convert(date, job.dateCreat, 103) desc;
样本数据:
1条答案
按热度按时间mutmk8jj1#
希望这对你有帮助