[英]SQL: How to count occurrences based on file extension
I have a query which returns a column of values: 我有一个查询,该查询返回一列值:
?????? ?? ?????? ??????? ?.?..xlsx
1028-13055 Single Patient Focus Wave 3.sav
2.xlsx
2011 BBQ (13Dec2013).sav
2014 Health IT Purchasing Intentions Survey Results.xlsx
2014 Safety Training and Safety Professionals Survey.sav
How do I count the number of occurrences based on the file extensions? 如何计算基于文件扩展名的出现次数? In the above example, we have three rows for the xlsx extension and two for the sav extension?
在上面的示例中,我们有三行用于xlsx扩展名,两行用于sav扩展名?
Try this: 尝试这个:
SELECT RIGHT(yourcolumnname,CHARINDEX('.', Reverse(yourcolumnname)) -1)
FROM yourtable
to isolate just the extension part and then count the occurrences 仅隔离扩展部分,然后计算出现次数
Please try: 请试试:
SELECT colcnt,
Count(*) TotCnt
FROM (SELECT RIGHT(col, Charindex('.', Reverse(col)) - 1) ColCnt
FROM yourtable)x
GROUP BY colcnt
Try this 尝试这个
SELECT extension,
Count(*) AS ExtensionCount
FROM (SELECT RIGHT(name, Charindex('.', Reverse(name)) - 1) AS Extension
FROM files) t
GROUP BY extension
SQL fiddle SQL小提琴
http://sqlfiddle.com/#!6/27269/5 http://sqlfiddle.com/#!6/27269/5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.