我的查询为每张票提供多行。我想在一行中列出所有自定义值。当我查询我的数据库时,我希望val.value
每个列都列为列,而不是每个列的多行ticket_id
ticket_id
我希望输出显示val.value
为列。
SELECT
ticket.ticket_id,ticket.`number`,ticket.dept_id,val.field_id,val.value,
ticket.staff_id,ticket.team_id,user.name, dept.dept_name,status.state,status.name as
status,ticket.source,ticket.isoverdue,ticket.isanswered,ticket.created
FROM ost_TICKET ticket
LEFT JOIN ost_ticket_status status ON status.id = ticket.status_id
LEFT JOIN ost_user user ON user.id = ticket.user_id
LEFT JOIN ost_department dept ON ticket.dept_id=dept.dept_id
LEFT JOIN ost_form_entry entry ON ticket.ticket_id = entry.object_id
LEFT JOIN ost_form_entry_values val ON entry.id = val.entry_id
输出如下:
ticket_id,number,dept_id,field_id,value,staff_id,team_id,name,dept_name,state,status,source,isoverdue,isanswered,created
4, 587202,4,3,NULL,15,0,Mark D,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09 4, 587202,4,4,NULL,15,0 ,Mark D,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09 4, 587202,4,87,NULL,15,0,Mark D,SalesDep,open,Open,Phone,0 ,0,10/14/2014 9:09 4, 587202,4,117,NULL,15,0,Mark D,SalesDep,open,打开,电话,0,0,10/14/2014 9:09 4, 587202, 4,20,Fish Farm,15,0,Mark D,SalesDep,open,Open,电话,0,0,10/14/2014 9:09 4, 587202,4,22,Normal,15,0,Mark D ,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09 4, 587202,4,73,nya-08-211,15,0,Mark D,SalesDep,open,Open,Phone, 0,0,10/14/2014 9:09 4, 587202,4,74,88,15,0,Mark D,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09 4 , 587202,4,84,Bara,15,0,Mark D,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09 4, 587202,4,85,Shaba,15,0, Mark D,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09 4, 587202,4,86,Kolkata,15,0,Mark D,SalesDep,open,Open,Phone,0, 0,10/14/2014 9:09 4, 587202,4,165,Tango,15,0,Mark D,SalesDep,open,Open,Phone,0,0,10/14/2014 9:09