select * from tb order by case when id='B' then 0 when id='A' then 1 else 2 end
select * from tb where where id = 'B' OR ID = 'A' OR ID = 'C'
select * from 表 order by charindex(rtrim(ID),'BAX')
select * from tb order by case id when 'B' then 1 when 'A' then 2 when 'C' then 3 else 4 end, [COUNT] DESC
select id from tb order by sum(count) desc
select * from t where id in ('B','A','C')? lz的意思是?
select * from 表 order by charindex(rtrim(ID),'BAC')
select ID,COUNT([COUNT]) FROM 表 group by [count]
select * from tb order by case id when 'B' then 1 when 'A' then 2 when 'C' then 3 else 4 end, [COUNT] DESC
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
不是。。就是要数量累加上。排序显示出来。 A B C 的总数比较显示。
SELECT [ID] ,Sum( [COUNT]) as T FROM [TB] Group by [ID] Order by T Desc
楼上可以。不过我希望SELECT 这里只能ID一个,因为我要写到IN()里进行查选到其它的表。
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')
from tb
order by case when id='B' then 0 when id='A' then 1 else 2 end
select * from 表
order by charindex(rtrim(ID),'BAX')
*
from
tb
order by
case id when 'B' then 1 when 'A' then 2 when 'C' then 3 else 4 end,
[COUNT] DESC
lz的意思是?
select * from 表
order by charindex(rtrim(ID),'BAC')
*
from
tb
order by
case id when 'B' then 1 when 'A' then 2 when 'C' then 3 else 4 end,
[COUNT] DESC
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
A B C 的总数比较显示。
SELECT [ID]
,Sum( [COUNT]) as T
FROM [TB]
Group by [ID] Order by T Desc
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')