提前抱歉这个愚蠢的问题,谢谢你的时间!
我有两个问题
查询A
SELECT sc.name +'.'+ta.name TableName
,SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa
ON pa.object_id = ta.object_id
INNER JOIN sys.schemas sc
ON ta.schema_id=sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name,ta.name
ORDER BY sum(pa.rows) DESC;
和
查询B
SELECT ta.name TableName
, ta.modify_date ModDate
, ta.max_column_id_used "Columns"
FROM sys.tables ta
ORDER BY ta.name;
执行罚款。
当我添加行
时, ta.modify_date ModDate
, ta.max_column_id_used "Columns"
我创建查询C
SELECT sc.name +'.'+ta.name TableName
,SUM(pa.rows) RowCnt
, ta.modify_date ModDate
, ta.max_column_id_used "Columns"
FROM sys.tables ta
INNER JOIN sys.partitions pa
ON pa.object_id = ta.object_id
INNER JOIN sys.schemas sc
ON ta.schema_id=sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name,ta.name
ORDER BY sum(pa.rows) DESC;
我收到错误
8120,Level 16,State 1,Line 3 列'sys.tables.modify_date'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
我理解聚合fx是什么以及GROUP BY的目的。
我是否需要创建子查询以将此信息包含在一个查询中