U-SQL 脚本获取多个 table 计数
U-SQL script to get multiple table count
需要一个 U-sql 脚本来获得多个 table 计数。
例如下面的查询给出了 Employees count 就像我想得到一个以上的 table count
@result =
SELECT COUNT(*) AS TotalRecordCount
FROM master.dbo.Employees;
OUTPUT @result
TO "/Output/ReferenceGuide/count/exampleA.csv"
USING Outputters.Csv();
您可以使用 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);
需要一个 U-sql 脚本来获得多个 table 计数。
例如下面的查询给出了 Employees count 就像我想得到一个以上的 table count
@result =
SELECT COUNT(*) AS TotalRecordCount
FROM master.dbo.Employees;
OUTPUT @result
TO "/Output/ReferenceGuide/count/exampleA.csv"
USING Outputters.Csv();
您可以使用 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);