我有一个更新的条目日志,其中每个票号都有不同类别的更新。 例如
|Ticket Number | DateTime | Update | Category |
| I0001 | 2015-07-28 | Spoke to someone | Update |
| I0002 | 2015-07-28 | Issue started | Update |
| I0002 | 2015-07-27 | Owner changed | System |
| I0002 | 2015-07-26 | Auto Alarm | System |
| I0001 | 2015-07-28 | More affected | Update |
| I0001 | 2015-07-25 | Auto Alarm | System |
| I0003 | 2015-07-01 | Assigneed | Update |
我希望它有一个列表,显示最后一个DateTime,每个票号和类别的更新,所以我最终会得到类似的东西。
|Ticket Number | DateTime | Update | Category |
| I0001 | 2015-07-28 | Spoke to someone | Update |
| I0002 | 2015-07-28 | Issue started | Update |
| I0002 | 2015-07-27 | Owner changed | System |
| I0001 | 2015-07-25 | Auto Alarm | System |
| I0003 | 2015-07-01 | Assigneed | Update |
我已经尝试了一些方法,但还没有接近完成它。
答案 0 :(得分:0)
<强>查询强>
select t2.`Ticket Number`,
t2.`DateTime`,
t2.`Update`,
t2.Category
from
(
select t.*,
@rownum := @rownum + 1 AS rn
from tableName t,
(select @rownum := 0) r
order by t.`Ticket Number`,`DateTime` desc
)t2
group by t2.`Ticket Number`,Category
having min(t2.rn)
order by t2.`DateTime` desc,t2.`Ticket Number`;
答案 1 :(得分:-1)
[WebInvoke(Method = "POST")]
这将为您提供每个故障单和类别的最新信息,如果您还包含[WebInvoke(Method = "POST",BodyStyle=WebMessageBodyStyle.WrappedRequest)]
字段,您将获得由于该组而获得的每张故障单的大量记录。
如果您想要一个与您发布的结果集匹配的查询,则必须使用子选择或排名功能来执行此操作。
select `Tickte number`, max(`datetime`), category from `table`
这未经过测试,但应该能满足您的需求。