我有类似下面的SQL查询:
SELECT COUNT(*) TheseMatch,
(SELECT COUNT(*) FROM [MyTable]) ThisIsMyTotal
FROM [MyTable]
WHERE MyCondition = 'MyCondition'
我正在尝试为此添加一个字符串文字,它将在同一个返回的行上提供。我一直在尝试这个:
SELECT 'THIS IS MY STRING' as Note,
SELECT COUNT(*) TheseMatch,
(SELECT COUNT(*) FROM [MyTable]) ThisIsMyTotal
FROM [MyTable]
WHERE MyCondition = 'MyCondition'
但是这会返回语法错误。显式指定字符串文字的正确方法是什么,并将其添加到结果中?
TIA!
答案 0 :(得分:2)
正确的语法类似于
SELECT 'THIS IS MY STRING' as Note,
COUNT(*) TheseMatch,
(SELECT COUNT(*) FROM [MyTable]) ThisIsMyTotal
FROM [MyTable]
WHERE MyCondition = 'MyCondition'
答案 1 :(得分:0)
SELECT 'THIS IS MY STRING' as Note,
SELECT COUNT(*) TheseMatch,
(SELECT COUNT(*) FROM Banks) ThisIsMyTotal
FROM Banks
WHERE Banks.Name = 'MyCondition'