sql - 如何从列表列表中选择最大出现的字符串?
问题描述
在我的数据库中,我有一个表。
statement= """create table itags(
tag_id number(10) not null primary key,
tag_name varchar2(50)
)"""
cur.execute(statement)
cur.execute("INSERT INTO itags VALUES(301,'Art')")
cur.execute("INSERT INTO itags VALUES(302,'Science')")
cur.execute("INSERT INTO itags VALUES(303,'Music')")
...
so on and so forth
...
现在我想选择并打印出现频率最高的标签名称。
如果我这样做:
cur.execute("select tag_name from itags")
res= cur.fetchall()
print(res)
我将获得一个包含我存储在该表中的标记名称的元组列表。例如:[(艺术,),(科学,),(音乐,),....]
现在我应该如何从这个元组列表中提取出现次数最多的字符串?此外,SQL 命令会比 python 代码更有帮助吗?
解决方案
Oracle 通过以下方式为您完成所有繁重的工作stats_mode
:
SELECT STATS_MODE(tag_name) FROM itags
推荐阅读
- javascript - toLocaleString() 不适用于输入更改
- hide - 如何正确使用 react-day-picker-input 中的 hideDayPicker() 公共函数?
- c# - c# Blob Triggered Azure Function V1 with "App Service Plan" 被触发了一些延迟
- azure - Azure 应用服务 - MVC5 WebApp 缺少 css 文件
- google-apps-script - 如何在 Apps 脚本中引用特定列
- ruby-on-rails - 如何在 ruby 1.8 和 rails 2.x 中合并参数中的值
- angular - ngu-carousel ponts 和 changeDetection 的问题
- c++ - Protobuf 动态和静态库
- c# - 检测VM是否被复制
- c# - 使用正则表达式替换字符串;