我想计算空列数或=''在SQL的每一行中。并按Row_ID
分组。
这样的事情:
SELECT
Row_ID, COUNT(*) AS 'cnt_blankCol'
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
table_catalog = 'db'
AND table_name = 'tblName'
AND COLUMNS IS NULL OR COLUMNS = ''
GROUP BY
Row_ID
ORDER BY
COUNT(*)
谢谢。
答案 0 :(得分:0)
Information_Schema tables are metadata tables that contain information about the database objects them selves, it does not contain the actual data from the tables, and it does not contain data aggregates per object.
This can not be done querying information_schema. Perhaps the Op can update the question and give a scenario of the goal of the question.
答案 1 :(得分:-1)
可根据要求自定义此脚本。
试试这个并告诉我你要找的是什么输出,
declare @tt table(id int identity,col int,col1 varchar(200))
insert into @tt VALUES(null,'gfdgdfg'),(32,'gfdgdfg'),(null,null)
--First make the datatype similar
--id can be rowid or rownumber function
;With CTEDataType as
(
SELECT cast(col as varchar(200))col, cast(col1 as varchar(200))col1,id
FROM @tt
)
, CTE as
(
SELECT id,ColName
FROM
(
SELECT isnull(col,'')col, isnull(col1,'')col1,id
FROM CTEDataType
) Main
UNPIVOT
(
ColName FOR ColNames IN (col ,col1)
) t4
)
select id,count(*)from CTE
where colname=''
group by id