Table a
ID int identity(1,1) key primary
Code VarChar(20) code 的值为 '100177','100248','100408','100178','100468','100357','100195' 中的任何值现在需要实现如下的排序
ID 从大到小(将最新的数据显示在最前面) CODE 按 '100177,100248,100408,100178,100468,100357,100195' 的顺序排如何实现 高手帮忙
ID int identity(1,1) key primary
Code VarChar(20) code 的值为 '100177','100248','100408','100178','100468','100357','100195' 中的任何值现在需要实现如下的排序
ID 从大到小(将最新的数据显示在最前面) CODE 按 '100177,100248,100408,100178,100468,100357,100195' 的顺序排如何实现 高手帮忙
DESC 降序
select *from 表 order by ID DESC
select '1'as a,*
into #TB
from TB where code='100177'insert into #TB
select '2',*
from TB where code='100248'
insert into #TB
select '3',*
from TB where code='100408'
insert into #TB
select '4',*
from TB where code='100178'
insert into #TB
select '5',*
from TB where code='100468'
insert into #TB
select '6',*
from TB where code='100357'insert into #TB
select '7',*
from TB where code='100195' select *from #TB
order by ID DESC ,a
对要么先code,后id才有意义select * from table_name order by Code asc,ID desc
ID ctDate PONO Charge Name Charge Code
--------------------------------------------------------------------------
2135 6月2日 805260130 Additional Item Charge 100195
2134 6月2日 805260130 Port Security Charge 100357
2133 6月2日 805260130 Port Construction 100468
2132 6月2日 805260130 Trucking-Empty (预提) 100178
2131 6月2日 805260130 Trucking Overnight Surcharge 100408
2130 6月2日 805260130 Customs Clearance 100248
2129 6月2日 805260130 Trucking 100177
2128 5月30日 805280046 Additional Item Charge 100195
2127 5月30日 805280046 Port Security Charge 100357
2126 5月30日 805280046 Port Construction 100468
2125 5月30日 805280046 Trucking-Empty (预提) 100178
2124 5月30日 805280046 Trucking Overnight Surcharge 100408
2123 5月30日 805280046 Customs Clearance 100248
2122 5月30日 805280046 Trucking 100177这里有两个PO 每个PO都对应着 7种费用。 (每次产生一个PO都会有7种费用对应,而这7种费用的代码为:
100195,100357,100468,100178,100408,100248,100177.
用户习惯了费用排列的顺序为:100177,100248,100408,100178,100468,100357,100195,同时将最后生成的一组PO 显示在最前面要求将上面的结果显示为下面的顺序:
ID ctDate PONO Charge Name Charge Code
--------------------------------------------------------------------------
2135 6月2日 805260130 Trucking 100177
2134 6月2日 805260130 Customs Clearance 100248
2133 6月2日 805260130 Trucking Overnight Surcharge 100408
2132 6月2日 805260130 Trucking-Empty (预提) 100178
2131 6月2日 805260130 Port Construction 100468
2130 6月2日 805260130 Port Security Charge 100357
2129 6月2日 805260130 Additional Item Charge 100195
2128 5月30日 805280046 Trucking 100177
2127 5月30日 805280046 Customs Clearance 100248
2126 5月30日 805280046 Trucking Overnight Surcharge 100408
2125 5月30日 805280046 Trucking-Empty (预提) 100178
2124 5月30日 805280046 Port Construction 100468
2123 5月30日 805280046 Port Security Charge 100357对于7楼的结果,我还没有看明白, 7楼以上无正确答案
Select
ID,ctDate,PONO,[Charge Name],[Charge Code]
order by ID DESC,charindex([Charge Code (FACT)],'100177,100248,100408,100178,100468,100357,100195')我只知道charindex([Charge Code (FACT)],'100177,100248,100408,100178,100468,100357,100195')可以对字符字段按指定的顺序排列,
但与ID的降序放在一起就不起效了,不知为什么?
Select
ID,ctDate,PONO,[Charge Name],[Charge Code]
order by ID DESC,charindex([Charge Code (FACT)],'100177,100248,100408,100178,100468,100357,100195')我只知道charindex([Charge Code (FACT)],'100177,100248,100408,100178,100468,100357,100195')可以对字符字段按指定的顺序排列,
但与ID的降序放在一起就不起效了,不知为什么?
2135 6月2日 805260130 Additional Item Charge 100195
后
2135 6月2日 805260130 Trucking 100177 排一下序,连数据也变了,确实不懂!!小声问句:有谁知道排序之后能改变数据的方法?楼上的,在问问题之前,请先确定你要什么,贴数据结果之前请先经过自己的大脑!
这样也不行.回Limpire :
我在9楼回复时的确是把数据贴错了,现在重新贴过:
下面是 order by ID DESC 的结果
ID ctDate PONO Charge Name Charge Code
--------------------------------------------------------------------------
2135 6月2日 805260130 Additional Item Charge 100195
2134 6月2日 805260130 Port Security Charge 100357
2133 6月2日 805260130 Port Construction 100468
2132 6月2日 805260130 Trucking-Empty (预提) 100178
2131 6月2日 805260130 Trucking Overnight Surcharge 100408
2130 6月2日 805260130 Customs Clearance 100248
2129 6月2日 805260130 Trucking 100177 2128 5月30日 805280046 Additional Item Charge 100195
2127 5月30日 805280046 Port Security Charge 100357
2126 5月30日 805280046 Port Construction 100468
2125 5月30日 805280046 Trucking-Empty (预提) 100178
2124 5月30日 805280046 Trucking Overnight Surcharge 100408
2123 5月30日 805280046 Customs Clearance 100248
2122 5月30日 805280046 Trucking 100177 要求将ctDate最近的PO放在最前面显示. 对于每个PO的费用要求按
100177,100248,100408,100178,100468,100357,100195 的先后顺序排列因此上面的结果应显示为如下顺序才是正确的
ID ctDate PONO Charge Name Charge Code
--------------------------------------------------------------------------
2129 6月2日 805260130 Trucking 100177
2130 6月2日 805260130 Customs Clearance 100248
2131 6月2日 805260130 Trucking Overnight Surcharge 100408
2132 6月2日 805260130 Trucking-Empty (预提) 100178
2133 6月2日 805260130 Port Construction 100468
2134 6月2日 805260130 Port Security Charge 100357
2135 6月2日 805260130 Additional Item Charge 100195 2122 5月30日 805280046 Trucking 100177
2123 5月30日 805280046 Customs Clearance 100248
2124 5月30日 805280046 Trucking Overnight Surcharge 100408
2125 5月30日 805280046 Trucking-Empty (预提) 100178
2126 5月30日 805280046 Port Construction 100468
2127 5月30日 805280046 Port Security Charge 100357
2128 5月30日 805280046 Additional Item Charge 100195有没有人能解决这个问题, 不够分可以另开新帖接散分,直到正解 !!
2、插入数据按照100177,100248,100408,100178,100468,100357,100195的顺序插入。
order by ctdate desc,pono,
casw code when 100177 then 1
when 100248 then 2
--...100408,100178,100468,100357,100195'
end
select '1'as a,*
into #TB
from TB where code='100177' insert into #TB
select '2',*
from TB where code='100248'
insert into #TB
select '3',*
from TB where code='100408'
insert into #TB
select '4',*
from TB where code='100178'
insert into #TB
select '5',*
from TB where code='100468'
insert into #TB
select '6',*
from TB where code='100357' insert into #TB
select '7',*
from TB where code='100195' select *from #TB
order by ID DESC ,a你结合以下 不可以吗?