需要一个U-sql脚本来获取多个表计数。
例如,以下查询为员工计数提供了类似的智慧,我想获得多个表计数
@result =
SELECT COUNT(*) AS TotalRecordCount
FROM master.dbo.Employees;
OUTPUT @result
TO "/Output/ReferenceGuide/count/exampleA.csv"
USING Outputters.Csv();
答案 0 :(得分:1)
您可以使用UNION:
@table =
SELECT * FROM
( VALUES
(1, "Smith", 20),
(1, "Smith", 20),
(1, "Smith", 20),
(2, "Brown", 30),
(3, "Case", 40)
) AS T(id, name, age);
@countonetable =
SELECT "table1" AS TableName,
COUNT(*) AS CountRows,
COUNT(DISTINCT name) AS CountNames
FROM @table;
OUTPUT @countonetable
TO @"/Output/countonetable.txt"
USING Outputters.Csv(quoting : false);
@countmanytables =
SELECT "table1" AS TableName, COUNT(DISTINCT name) AS TableCount FROM @table
UNION
SELECT "table2" AS TableName, COUNT(*) AS TableCount FROM @table;
OUTPUT @countmanytables
TO @"/Output/countmanytables.txt"
USING Outputters.Csv(quoting : false);