Select语句问题

时间:2015-02-20 17:52:45

标签: c# sql-server select

我正在尝试select the top 1此选择查询然后订购DESC,我尝试的每一种方式,它似乎都不起作用。这是我的代码:

SELECT '$' + CONVERT(VARCHAR(50),
CONVERT(MONEY, COALESCE(([amount]), 0)),
1) AS [Total]
FROM [myTable] a
left join [mySecondTable]  b on a.[ID] = b.[ID]
left join [myThirdTable c on c.[myNumber] = b.[myNumber]

WHERE c.[myName] = 'me'

如果我想选择前1 amount,然后按amountSELECT TOP 1ORDER By [amount] DESC进行排序,我会在哪里准确地填写它们?或者这甚至是正确的方法吗?

1 个答案:

答案 0 :(得分:0)

你的ORDER BY将在最后,而在开头的前1位。

SELECT top 1 '$' + CONVERT(VARCHAR(50),
CONVERT(MONEY, COALESCE(SUM([amount]), 0)),
1) AS [Total]
FROM [myTable] a
left join [mySecondTable]  b on a.[ID] = b.[ID]
left join [myThirdTable c on c.[myNumber] = b.[myNumber]

WHERE c.[myName] = 'me'
order by [AMOUNT] DESC