有一个表 table1 ,其中一个字段名是 field1 , 该字段的值有:'移动','联通','网通','电信' 4种值,现在我用group by语句查询属于各个运营商的记录都有多少:
select count(*),field1 from table1 group by field1;
这样查询出来的数据会自动按照字段值的字母顺序排列,如下:
count(*) field1
-------- -------
34 电信
12 联通
55 网通
9 移动他们的排列顺序就是按照首字母 D,L,W,Y 来排序的,如果想让提出来的数据按照特定的顺序排列 ,像这样:
count(*) field1
-------- -------
9 移动
12 联通
34 电信
55 网通该如何做 ?????
select count(*),field1 from table1 group by field1;
这样查询出来的数据会自动按照字段值的字母顺序排列,如下:
count(*) field1
-------- -------
34 电信
12 联通
55 网通
9 移动他们的排列顺序就是按照首字母 D,L,W,Y 来排序的,如果想让提出来的数据按照特定的顺序排列 ,像这样:
count(*) field1
-------- -------
9 移动
12 联通
34 电信
55 网通该如何做 ?????
order by decode(field1,'移动',1,'联通',2,'电信',3,'网通',4)
table1,field1,field2,field3 , field2 的取值 '资费争议','通信质量' , field3 的取值 '企业责任','非企业责任' , 如果按照三个字段分组,自动排序的结果如下:
select count(*),field1,field2,field3 from table1 group by field1,field2,field3;count(*) field1 field2 field3
-------- ------- --------- ------
8 电信 通信质量 非企业责任
12 电信 通信质量 企业责任
5 电信 资费争议 非企业责任
9 电信 资费争议 企业责任
15 联通 通信质量 非企业责任
4 联通 通信质量 企业责任
22 联通 资费争议 非企业责任
7 联通 资费争议 企业责任
..................如果让field2 和 field3 字段 也按照 特定的顺序显示,该如何????
order by decode(field1,'移动',1,'联通',2,'电信',3,'网通',4),
decode(field2,'通信质量',1....),
declde(field3,'非企业责任'1,..)
一样的写就行了