很难的SQL语句,请大家帮忙!(100)

  • 主题发起人 主题发起人 zhao_auau
  • 开始时间 开始时间
Z

zhao_auau

Unregistered / Unconfirmed
GUEST, unregistred user!
在查询分析器运行:select 0 As Code, Null As ParentCode, '全部' As Name, Null As Finished, Null As Accepted, Null As CallTypeUnion Allselect -1 As Code, 0 As ParentCode, '来信' As Name, Null As Finished, Null As Accepted, '来信' As CallTypeUnion Allselect -2 As Code, 0 As ParentCode, '来访' As Name, Null As Finished, Null As Accepted, '来访' As CallTypeUnion Allselect -3 As Code, 0 As ParentCode, '来电' As Name, Null As Finished, Null As Accepted, '来电' As CallTypeUnion AllSelect a.Code * 10 + b.Code, a.ParentCode, b.Name, b.Finished, b.Accepted, a.NameFrom (select 1 As Code, -1 As ParentCode, '来信' As Name Union All select 2 As Code, -2 As ParentCode, '来访' As Name Union All select 3 As Code, -3 As ParentCode, '来电' As Name) a, (select 1 As Code, -1 As ParentCode, '已受理并解决' As Name, 1 As Finished, 1 As Accepted Union All select 2 As Code, -2 As ParentCode, '已受理未解决' As Name, 0 As Finished, 1 As Accepted Union All select 3 As Code, -3 As ParentCode, '不受理' As Name, 0 As Finished, 0 As Accepted) b就会查询出一个数据集。得出:0 NULL 全部 NULL NULL NULL-1 0 来信 NULL NULL 来信-2 0 来访 NULL NULL 来访-3 0 来电 NULL NULL 来电11 -1 已受理并解决 1 1 来信12 -1 已受理未解决 0 1 来信13 -1 不受理 0 0 来信21 -2 已受理并解决 1 1 来访22 -2 已受理未解决 0 1 来访23 -2 不受理 0 0 来访31 -3 已受理并解决 1 1 来电32 -3 已受理未解决 0 1 来电33 -3 不受理 0 0 来电有没有办法在全部下面增加一个年度。每个年度下面都有全部下面的这些树枝。
 
继续union all 年度啊。
 
union 年度,select 前面放个序号列,年度最大,order by 年度
 
后退
顶部