Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

ms access - SQL - Count and sorted by one column

Need help on getting the count out for a Table in Access and grouping them by that particular type.

Example, I have this table

Table

I need it to output in a query into this:

Query Output


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need conditional aggregation as follows:

select itemname, itemtype,
       count(case when building = 'A' then 1 end) as totalA,
       count(case when building = 'B' then 1 end) as totalB,
       count(case when building = 'C' then 1 end) as totalC
  from your_table
group by itemname, itemtype
order by itemname, itemtype, totalA desc, totalB desc, totalC desc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...