计算多列中的出现次数

编程入门 行业动态 更新时间:2024-10-22 17:28:47
本文介绍了计算多列中的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试计算表中多个列的出现次数.所有值都是整数,所有数字在每一行中都是唯一的. (即您不会在同一行中出现两个值)表结构为:

Im trying to count occurrences across multiple columns in a table. All values are integers and all the numbers are unique in each row. (i.e you won't get two values occurring in the same row) The table structure is:

ID Number1 Number2 Number3 Number4 Number5 Number6 --------------------------------------------------------- 11 6 4 5 9 8 6 9 11 5 3 15 8 5 9 11 4 6 4 11 17 3 7 1

预期输出为:

Number Count -------------- 11 4 6 3 4 3 5 3 9 3 3 2 8 2 15 1 17 1 7 1 1 1

我尝试使用Internet上的数据透视和其他各种方法,但似乎无法使其正常工作.任何想法,似​​乎都是一个简单的查询,但是我做对了.

I've tried using pivots and various other methods found on the internet but just can't seem to get it working correctly. Any ideas, it seems like a simple query but I just can't get it right.

推荐答案

如果只有6列,则可以采用一种方法

If there are only 6 columns, then one way you can do this

select Number, count(*) From (select Number1 as Number from your_table union all select Number2 as Number from your_table union all select Number3 as Number from your_table union all select Number4 as Number from your_table union all select Number5 as Number from your_table union all select Number6 as Number from your_table) myTab group by Number;

更多推荐

计算多列中的出现次数

本文发布于:2023-10-28 19:32:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537577.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:次数   多列中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!