C# DataTable排序有关问题

C# DataTable排序问题
我从数据库查询出来的数据格式为

  id

  12
  12
  12
  12
  11
  11
  11

我在c#里面用datatable来接受它,并且根据元素出现重复的次数来排序,结果为:12,11,因为12出现4次,而11出现三次,所以12排在11的前面,明白嘛?

多谢!!

------解决方案--------------------
那你查询时,sql中增加一个信息,count(*) group by id ,然后根据这个值排序
------解决方案--------------------
SQL code

declare  @table  table(id int)
insert into @table 
select 12 union all
select 11 union all
select 11 union all
select 12 union all
select 12 union all
select 12

select list.* from @table list
LEFT JOIN
(
    select id,COUNT(1) cou from @table group by id 
) T ON T.id = list.id
order by T.cou DESC


/*

(6 行受影响)
id
-----------
12
12
12
12
11
11

(6 行受影响)

*/

------解决方案--------------------
探讨
我从数据库查询出来的数据格式为

id

12
12
12
12
11
11
11

我在c#里面用datatable来接受它,并且根据元素出现重复的次数来排序,结果为:12,11,因为12出现4次,而11出现三次,所以12排在11的前面,明白嘛?

多谢!!

------解决方案--------------------
SQL code

create table #table (id int)
insert into #table 
select 12 union all
select 11 union all
select 11 union all
select 12 union all
select 12 union all
select 12

select id,count(1) as c from #table group by id order by c desc
/*
12    4
11    2
*/

------解决方案--------------------
SQL code

select id,COUNT(id) from @table group by id ORDER BY COUNT(id) DESC