Tsql 按特定字符串值对数据进行排序 [英] Tsql ordering data by specific string values

查看:30
本文介绍了Tsql 按特定字符串值对数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个审计表,其中包含用于插入、更新和删除操作的数据.我正在编写一个报告,它将按插入、更新和删除的顺序显示数据.我认为 order by 条款不会有帮助.有什么帮助吗?

I have an audit table that have data for insert, update and delete operations. I am writing a report that will display data in the order of Insert, Update and Delete. I don't think the order by clause will help. any help?

推荐答案

您可以将 ORDER BY 与 CASE 子句:

You can use an ORDER BY combined with a CASE clause:

SELECT *
FROM auditlog
ORDER BY CASE operation_type
    WHEN 'Insert' THEN 1
    WHEN 'Update' THEN 2
    WHEN 'Delete' THEN 3
END

这篇关于Tsql 按特定字符串值对数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆