字段数据比如是这样。
ID  COUNT
A     4
B     3
C     2
B     5
C     1我想查询出来 显示的ID 是B A C 显示出来。想问下SQL如何写。谢谢。

解决方案 »

  1.   

    select * from tb order by charindex(id,'bac')
      

  2.   

    select *
    from tb
    order by case when id='B' then 0 when id='A' then 1 else 2 end
      

  3.   

    select * from tb where where id = 'B' OR ID = 'A' OR ID = 'C'
      

  4.   


    select * from 表
    order by charindex(rtrim(ID),'BAX')
      

  5.   

    select 
      *
    from 
      tb
    order by
      case id when 'B' then 1 when 'A' then 2 when 'C' then 3 else 4 end,
      [COUNT] DESC
      

  6.   

    select id from tb order by sum(count) desc
      

  7.   

    select * from t where id in ('B','A','C')?
    lz的意思是?
      

  8.   


    select * from 表
    order by charindex(rtrim(ID),'BAC')
      

  9.   

    select ID,COUNT([COUNT]) FROM  表 group by [count]
      

  10.   

    select 
      *
    from 
      tb
    order by
      case id when 'B' then 1 when 'A' then 2 when 'C' then 3 else 4 end,
      [COUNT] DESC
      

  11.   


    CREATE TABLE TESTTB (ID CHAR(1) , COUNTE INT )
    INSERT TESTTB
    SELECT 'A',4 UNION
    SELECT 'B',3 UNION
    SELECT 'C',2 UNION
    SELECT 'B',5 UNION
    SELECT 'C',1 SELECT ID FROM TESTTB GROUP BY ID ORDER BY MAX(COUNTE) DESCB
    A
    C
      

  12.   

    不是。。就是要数量累加上。排序显示出来。
    A B C 的总数比较显示。 
      

  13.   


    SELECT [ID]
          ,Sum( [COUNT]) as T
      FROM [TB]
     Group by [ID] Order by T Desc
      

  14.   

    楼上可以。不过我希望SELECT 这里只能ID一个,因为我要写到IN()里进行查选到其它的表。
      

  15.   

    if object_id('test') is not null drop table test
    create table test
    (
    Id varchar(1),
    counts int
    )
    GO
    insert into test
    select 'A',4 union all
    select 'B',3 union all
    select 'C',2 union all
    select 'B',5 union all
    select 'C',1select * from test order by charindex(id,'BAC')