Select Count(*)
From (
Select ...
From TempTable
Group By column_1, column_2, column_3, column_4
) As Z
另一个解决方案是使用 Count District:
Select ...
, ( Select Count( Distinct column_1, column_2, column_3, column_4 )
From TempTable ) As CountOfItems
From TempTable
Group By column_1, column_2, column_3, column_4
select column_group_by,count(*) as Coulm_name_to_be_displayed from Table group by Column;
-- For example:
select city,count(*) AS Count from people group by city
select *
, concat(cast(cast((ThirdTable.Total_Records_in_Group * 100 / ThirdTable.Total_Records_in_baseTable) as DECIMAL(5,2)) as varchar), '%') PERCENTage
from
(
SELECT FirstTable.FirstField, FirstTable.SecondField, SecondTable.Total_Records_in_baseTable, count(*) Total_Records_in_Group
FROM BaseTable FirstTable
JOIN (
SELECT FK1, count(*) AS Total_Records_in_baseTable
FROM BaseTable
GROUP BY FK1
) SecondTable
ON FirstTable.FirstField = SecondTable.FK1
GROUP BY FirstTable.FirstField, FirstTable.SecondField, SecondTable.Total_Records_in_baseTable
ORDER BY FirstTable.FirstField, FirstTable.SecondField
) ThirdTable