我正在尝试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
,然后按amount
与SELECT TOP 1
和ORDER By [amount] DESC
进行排序,我会在哪里准确地填写它们?或者这甚至是正确的方法吗?
答案 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