我现在要写一条查询的SQL语句,试了很长时间还是没写出来,现求各位帮忙了~
假设有如下表格t_context,其中type共有A、B、C种类型,优先级依次为B>A>C,现在要查询该表格中的所有数据,不过须按如下规则排序:
1、类型为B的排在第一,若有多条则按时间递减;
2、类型为A的排在第二,若有多条则按时间递减;
3、剩下的则按时间递减即可。
id | type | date | context |
1 | C | xxxx-xx-xx xx:xx:xx | ... |
2 | C | xxxx-xx-xx xx:xx:xx | ... |
3 | A | xxxx-xx-xx xx:xx:xx | ... |
4 | C | xxxx-xx-xx xx:xx:xx | ... |
5 | B | xxxx-xx-xx xx:xx:xx | ... |
6 |
A |
xxxx-xx-xx xx:xx:xx | ... |
怎样用一条select语句实现这种规则的排序结果?