想要在一行中显示名称,项目名称和日期。
╔═══════╦════════════════╦═══════════════╦════════╗
║ name ║ empid ║ projectname ║ date ║
╠═══════╬════════════════╬═══════════════╬════════╣
║ krish ║ 1 ║ Num. 1 ║12/5/19 ║
║ krish ║ 1 ║ Num. 2 ║11/5/19 ║
║ krish ║ 1 ║ Num. 3 ║11/5/19 ║
║ krish ║ 1 ║ Num. 4 ║11/5/19 ║
║ selva ║ 2 ║ Num. 5 ║12/5/19 ║
║ selva ║ 2 ║ Num. 6 ║11/5/19 ║
╚═══════╩════════════════╩═══════════════╩════════╝
我有这样的表,但我想显示
╔═══════╦════════════════╦═══════════════=╦════════╗
║ name ║ empid ║ projectname ║ date ║
╠═══════╬════════════════╬══════════════=═╬════════╣
║ krish ║ 1 ║ Num. 1 ║12/5/19 ║
║ krish ║ 1 ║Num.2,Num3,Num 4║11/5/19 ║
║ selva ║ 2 ║ Num. 5 ║12/5/19 ║
║ selva ║ 2 ║ Num. 6 ║11/5/19 ║
SELECT tblprojects.id as pid,tblemployees.FirstName,tblemployees.LastName,tblemployees.EmpId,tblemployees.id,tblprojects.Project,tblprojects.PostingDate,tblprojects.Status
from tblprojects
join tblemployees
on tblprojects.empid=tblemployees.id
order by pid desc
╔═══════╦════════════════╦═══════════════=╦════════╗
║ name ║ empid ║ projectname ║ date ║
╠═══════╬════════════════╬══════════════=═╬════════╣
║ krish ║ 1 ║ Num. 1 ║12/5/19 ║
║ krish ║ 1 ║Num.2,Num3,Num 4║11/5/19 ║
║ selva ║ 2 ║ Num. 5 ║12/5/19 ║
║ selva ║ 2 ║ Num. 6 ║11/5/19 ║
最佳答案
GROUP_CONCAT
用于通过concat在单个字符串中合并结果
SELECT tblprojects.id as pid,tblemployees.FirstName,tblemployees.LastName,tblemployees.EmpId,tblemployees.id,GROUP_CONCAT(tblprojects.Project),tblprojects.PostingDate,tblprojects.Status
from tblprojects
join tblemployees
on tblprojects.empid=tblemployees.id
GROUP BY tblprojects.PostingDate
order by pid desc
关于php - 想要使用php和mysql将员工今天的任务单行执行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56218522/