The following select statement gives me a table with overtime greater than 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;
[![Output][1]][1]
Now I want to join the empid with another table(t3) where I have to concatenate the first name and last name and then join it to the above table.
[![This table][2]][2]
I cant seem to figure out how to join both these select statement and keep running into errors
use your query as a sub-query and join with table t3 ans use concat
function
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
Try below using join with employees_2 table
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;
Try this:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.