Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 SQL Server 我试图将问卷表总结如下,但我很挣扎!
我想按月和年显示所有问卷中回答正确的百分比。
任何人都可以帮忙吗?
您可以使用条件聚合来做到这一点。此方法显示有条件地使用avg():
avg()
select "Year", "Month", avg(case when recommend = 'true' then 1.0 else 0.0 end) * 100 as "True %" from Questionnaire q group by "Year", "Month" order by "Year", "Month";
如果您实际上想要最后的“%”,则需要将结果转换为字符串并附加它。