簡體   English   中英

給定一條選擇語句,我該如何再選擇更多?

[英]Given a select statement how do i subselect more?

以下選擇語句為我提供了加班時間大於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語句同時加入並繼續遇到錯誤

將您的查詢用作子查詢,並與表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

嘗試在下方使用join with employee_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;

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM