按十进制值对不同的字符串值进行排序

时间:2017-11-15 10:44:09

标签: sql-server sql-server-2014

我有以下查询:

//Sandcastle_Begin
var terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
requestVertexNormals : true
});

var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider : terrainProvider,
baseLayerPicker : false
});

var options = {
    camera : viewer.scene.camera,
    canvas : viewer.scene.canvas
};

Sandcastle.addToolbarMenu([{
    text : 'Lateral avoidance w. real Wx and waypoints (KJFK-LEBL)',
    onselect : function() {

        viewer.camera.flyHome(0); 

        viewer.dataSources.add(Cesium.CzmlDataSource.load('./SampleData/interp_turb_data_fromFede_avoid_realistic_w_waypoints.czml')).then(function(ds) {

        var entity = ds.entities.getById('path');

        // viewer.trackedEntity = entity;

        entity.orientation =  new Cesium.VelocityOrientationProperty(entity.position);

        entity.position.setInterpolationOptions({
            interpolationDegree : 1,
            interpolationAlgorithm : Cesium.HermitePolynomialApproximation
          });    
    });

    }
}], 'toolbar');

Sandcastle.reset = function() {
    viewer.dataSources.removeAll();
    viewer.clock.clockRange = Cesium.ClockRange.UNBOUNDED;
    viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK;
};
//Sandcastle_End

FUNDING_FEE_AMOUNT 是十进制列,但当它被转换为 VARCHAR 时,当 ORDER BY 将其作为字符串排序时,所以2> 19.我通常会在没有强制转换的情况下通过 FUNDING_FEE_AMOUNT 订购,但在这种情况下我不能这样做,因为 DISTINCT 关键字,我不能删除转换,因为我会无法添加“;”作为分隔符。

所以问题是,如何连接这些值但是具有类似数字的顺序?

1 个答案:

答案 0 :(得分:2)

您可以使用data()代替text(),它会在连接值之间为您提供空格,然后只需用';'替换空格,这样就不会将decimal转换为varchar并且会给出正确的顺序。

以下是一个例子:

declare @t table (col decimal(10, 2));
insert into @t values (100.05), (11.01), (2.33), (20), (1);

select replace((  select distinct col  as 'data()' from @t order by col for xml path('')  ), ' ', ';') as res