选择每个序列的名字

时间:2015-12-09 18:18:58

标签: sql sql-server

我有以下查询:

-- set up test table
Declare @TEST TABLE(Name VarChar(100), Sequence VarChar(500))

-- insert test data
INSERT INTO @TEST (Name,Sequence) SELECT 'A_01' , 'AAAAAAAAAAAAAAAAAAAAAAAAAAA'
INSERT INTO @TEST (Name,Sequence) SELECT 'A_02' , 'AAAAAAAAAAAAAAAAAAAAAAAAAAA'
INSERT INTO @TEST (Name,Sequence) SELECT 'A_03' , 'AAAAAAAAAAAAAAAAAAAAAAAAAAA'
INSERT INTO @TEST (Name,Sequence) SELECT 'A_04' , 'TTTTTTTTTTTTTTTTTTTTTTTTTTT'
INSERT INTO @TEST (Name,Sequence) SELECT 'A_05' , 'TTTTTTTTTTTTTTTTTTTTTTTTTTT'
INSERT INTO @TEST (Name,Sequence) SELECT 'A_06' , 'GGGGGGGGGGGGGGGGGGGGGGGGGGG'
INSERT INTO @TEST (Name,Sequence) SELECT 'A_07' , 'CCCCCCCCCCCCCCCCCCCCCCCCCCC'

-- select test data
SELECT Name, Sequence FROM @TEST ORDER BY Name, Sequence

结果:

 Name                           Sequence
 A_01                    AAAAAAAAAAAAAAAAAAAAAAAAAAA
 A_02                    AAAAAAAAAAAAAAAAAAAAAAAAAAA
 A_03                    AAAAAAAAAAAAAAAAAAAAAAAAAAA
 A_04                    TTTTTTTTTTTTTTTTTTTTTTTTTTT
 A_05                    TTTTTTTTTTTTTTTTTTTTTTTTTTT
 A_06                    GGGGGGGGGGGGGGGGGGGGGGGGGGG
 A_07                    CCCCCCCCCCCCCCCCCCCCCCCCCCC

如何编写查询以删除具有重复Sequence值的行,同时仍保留Name附带的第一个Sequence

 Name                           Sequence
 A_01                    AAAAAAAAAAAAAAAAAAAAAAAAAAA
 A_04                    TTTTTTTTTTTTTTTTTTTTTTTTTTT
 A_06                    GGGGGGGGGGGGGGGGGGGGGGGGGGG
 A_07                    CCCCCCCCCCCCCCCCCCCCCCCCCCC

2 个答案:

答案 0 :(得分:1)

// GeoServer upload

var http = require('http'); 
var auth = 'Basic ' + new Buffer('admin' + ':' + 'geoserver').toString('base64');
//build the object to post
var post_data = (path.join(paperpath, paperid, "geotiff", req.files["otherfiles"][fileno].originalname)); // Path to .tif file

var s = JSON.stringify(post_data);
var post_options = {
  host: 'localhost',
  port: '9000',
  path: '/geoserver/rest/workspaces/myWorkspace/coveragestores/test/file',
  method: 'POST',
  headers: {
    'Content-Length': s.length,
    'Content-Type': 'image/tif',
    'Authorization': auth
  }
}
  // Set up the request
var post_req = http.request(post_options, function(res) {
  res.setEncoding('utf8');
  console.log(res.statusCode);

  res.on('data', function(chunk) {
    console.log('Success! ' + chunk);
  });
});
// post the data
post_req.write(s);
post_req.end();

答案 1 :(得分:0)

试试这个:

SELECT DISTINCT Name, Sequence FROM @TEST ORDER BY Name, Sequence