我正面临着尝试编写查询的问题.
我的表格如下:
tblTicketIssues TicketID | RequesterID tblPersonnelProfile PersonnelID | FirstName | LastName tblTicketAttribute TicketID | Attribute | AttributeValue
我必须显示以下字段:
TicketID, RequesterFullName, UrgentPriorityID, MediumPriorityID, LowPrioritytID
这是具有挑战性的部分:
如果tblTicketAttribute.Attribute ="Urgent",那么来自tblTicketAttribute.AttributeValue的值将显示在UrgentPriority列中
如果tblTicketAttribute.Attribute ="Medium",那么来自tblTicketAttribute.AttributeValue的值将显示在MediumPriority列中
如果tblTicketAttribute.Attribute ="Low",那么来自tblTicketAttribute.AttributeValue的值将显示在LowPriority列中
值tblTicketAttribute.Attribute
包括" 紧急 "," 中 "," 低 "," 超过30 "," 超过60 "," 超过90 "," 已关闭 "
我怎样才能做到这一点?
查看CASE声明.
select ticketID ,Lastname +', '+firstname ,CASE attribute WHEN 'Urgent' THEN attributeValue ELSE '' END as UrgentPriorityID ,CASE attribute WHEN 'Medium' THEN attributeValue ELSE '' END as MediumPriorityID ,CASE attribute WHEN 'Low' THEN attributeValue ELSE '' END as LowPrioritytID from ...