按TABLE_SCHEMA分组,按TABLE_NAME排序

时间:2016-05-15 09:15:29

标签: sql sql-server

我尝试按顺序拥有所有Table_Schema名称,然后为每个table_schema命令table_Name。我这样试试:

SELECT TABLE_SCHEMA , TABLE_NAME, (TABLE_TYPE)  
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_type = 'BASE TABLE'
GROUP BY TABLE_SCHEMA
ORDER BY TABLE_NAME DESC

谢谢

1 个答案:

答案 0 :(得分:1)

GROUP BY实际上将所有类似的查询结果“汇总”为一行。 https://msdn.microsoft.com/en-us/library/ms177673.aspx

您只需要一个包含两列的订单。试试这个:

SELECT TABLE_SCHEMA , TABLE_NAME, (TABLE_TYPE)  
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_type = 'BASE TABLE'
ORDER BY TABLE_SCHEMA, TABLE_NAME