1
SELECT ORG.DESCRIPTION, ORG.EXTERNALKEY
FROM organization org
WHERE org.ownerid = (SELECT id
                      FROM organization
                     WHERE externalkey = '970000')
     OR org.externalkey = '970000'
ORDER BY org.description;

这是我的 sql 查询。我使用了“ORDER BY org.description”。但这并不是我的要求。我想在查询结果中创建第一个 (org.externalkey='970000')。行将被排序(但 org.externalkey='970000' 行将是第一个)。怎么做?

4

2 回答 2

5

尝试这个:

您只需要在 ORDER BY CLAUSE 中添加 CASE 语句

 ORDER BY 
 CASE WHEN externalkey = '970000' THEN 0 else 1 END,
           org.description
于 2012-09-03T10:42:10.160 回答
0

尝试这个:

SELECT ORG.DESCRIPTION, ORG.EXTERNALKEY
FROM organization org
WHERE org.ownerid = (SELECT id
                      FROM organization
                     WHERE externalkey = '970000')
     OR org.externalkey = '970000'
ORDER BY org.externalkey ,org.description;
于 2012-09-03T10:42:19.117 回答