以下选择语句为我提供了加班时间大于80的表:
SELECT empid,overtime FROM(SELECT empid, IF(SUM(slength)>80,SUM(slength)-80,0)
as 'overtime' from schedule_2 group by empid) as t
where overtime >0;
[![输出] [1]] [1]
现在,我想将Empid与另一个表(t3)联接在一起,在这里必须将名字和姓氏连接起来,然后将其联接到上面的表中。
[![此表] [2]] [2]
我似乎无法弄清楚如何将这两个select语句连接在一起并不断遇到错误
答案 0 :(得分:0)
将您的查询用作子查询,并与表t3结合使用并使用concat
函数
select t1.empid,
concat(t3.firstname,t3.lastname) as name,
t1.overtime from
(
select * from
(
SELECT empid, IF(SUM(slength)>80,SUM(slength)-80,0)
as overtime from schedule_2 group by empid
) as t
where overtime >0
) as t1 join t3 on t1.empid=t3.empid
答案 1 :(得分:0)
请尝试以下使用“与employees_2表联接”
SELECT t.empid,overtime,concat(firstname,' ',lastname) as empname
FROM
(SELECT empid, IF(SUM(slength)>80,SUM(slength)-80,0)
as 'overtime' from schedule_2 group by empid) as t
inner join employees_2 t1 on t.empid=t1.empid
where overtime >0;
答案 2 :(得分:0)
尝试一下:
select empid, fullName, overtime
from (
SELECT empid,
overtime
FROM (
SELECT empid,
IF(SUM(slength)>80,SUM(slength)-80,0) as overtime
from schedule_2 group by empid
) as t where overtime > 0
) a join (
select concat(firstName, ' ', lastName) fullName,
empid
from employees_2
) b on a.empid = b.empid