यह:
select final.deptId, d.deptName,
e3.employeename + ',' + cast(e3.salary as varchar) employee
from employee e3
left join (
select e1.id, e1.deptId from employee e1
left join employee e2
on e1.deptId = e2.deptId and e1.id > e2.id
where e2.id is null
) final on e3.id = final.id
left join department d on d.id = final.deptId
इसमें परिणाम:
+--------+----------+-------------+ | DEPTID | DEPTNAME | EMPLOYEE | +--------+----------+-------------+ | 1 | IT | John,10000 | | | | Bob,15000 | | 2 | CSE | Akon,12000 | | | | Smith,20000 | +--------+----------+-------------+
ध्यान दें कि "रिक्त" मान वास्तव में null
. से भरे हुए हैं मान।
अगर आपको इससे कोई समस्या है तो मुझे बताएं।