8

我有这样的查询

SELECT COUNT(ID) 'Records Affected', TYPE FROM MASTER
GROUP BY TYPE

这个的输出是

Records Affected            TYPE
----------------            ---- 
4                            F1
3                            F2
5                            F3

现在我想更改查询,以便输出如下

Records Affected
----------------
The number of records affected for F1 is : 4 
The number of records affected for F2 is : 3
The number of records affected for F3 is : 5

"The number of records affected for " + TYPE + " is : " + COUNT.

如何将默认文本添加到结果集的每一行而不是附加到前端。我想简化仅将 DataGrid 中的记录显示为摘要的任务。

4

5 回答 5

13

您可以使用以下内容轻松连接字符串。您将使用 将+字符串连接到type列和count. 请注意,count需要将其转换为 avarchar才能正常工作:

SELECT 
  'The number of records affected for '+ type +
    ' is : '+ cast(COUNT(ID) as varchar(50)) as'Records Affected'
FROM yt
GROUP BY TYPE;

请参阅带有演示的 SQL Fiddle

于 2013-06-06T14:43:56.480 回答
2

只需将文本放入查询中:

SELECT 'The number of records affected for ' + TYPE + ' is : ' + CAST(COUNT(ID) as VARCHAR(20)) AS 'Records Affected' FROM MASTER
GROUP BY TYPE
于 2013-06-06T14:45:30.310 回答
1
SELECT "The number of records affected for " + TYPE + " is : " + COUNT(ID) AS [Records Affected]
FROM Master 
GROUP BY TYPE
于 2013-06-06T14:48:49.290 回答
0

试试这个:

SELECT 'The number of records affected for ' + TYPE + ' is : ' + 
STR(X.[Records Affected]) AS [Records Affected]
FROM (SELECT COUNT(ID) 'Records Affected', TYPE FROM MASTER GROUP BY TYPE) X
于 2013-06-06T14:43:44.617 回答
0

使用此查询:

UPDATE bookmark_linx SET link_url=(SELECT CONCAT(link_url, '?raw=true')) WHERE link_url LIKE '%dropbox%'
于 2016-12-23T05:19:25.217 回答