mysql unique count_MySQL - Count Number of Unique Values
问题
If I have three columns:
orderNumber, name, email
and I would like to count how many unique emails are in the table how would I go about doing so?
A statement like:
SELECT count(email) FROM orders
gives me the total count.
I tried SELECT DISTINCT count(email) FROM orders
but that does not seem to be giving me the numbers I am expecting.
回答1:
use
SELECT count( DISTINCT(email) ) FROM orders
Distinct provide unique email ids and then simply count them.
回答2:
SELECT count(DISTINCT(email)) FROM orders
its different from your posting, since its filters out the duplicates before counting it
回答3:
For best performance you should use:
SELECT
sub.email,
count(1) as 'count_unique'
FROM
(SELECT email FROM orders GROUP by email) sub
回答4:
The accepted soultion doesn't work for me - it returns a "1" for each unique email address in the table.
This is what I had to do to get the info I needed:
select email, count(email) AS total from sysAccessLog group by email order by total desc
Which returns a list of email addresses and the number of occurrences.
来源:https://stackoverflow.com/questions/16697215/mysql-count-number-of-unique-values
mysql unique count_MySQL - Count Number of Unique Values相关推荐
- pandas使用nunique函数计算dataframe每个数据列的独特值的个数(count number of unique values in each column of dataframe)
pandas使用nunique函数计算dataframe每个数据列的独特值的个数(count number of unique values in each column of dataframe) ...
- LeetCode 357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits Given a non-negative integer n, count all numbers with unique ...
- Number of unique ways that ATM can tender
An atm can only dispense values of $1, $5, $20, and $50. Return the number of unique ways that a $ ...
- mysql unique的用法_MySQL使用UNIQUE实现数据不重复插入
SQL UNIQUE 约束 UNIQUE 约束唯一标识数据库表中的每条记录. UNIQUE 和 PRIMARY KEY 约束均为列或列集合提供了唯一性的保证. PRIMARY KEY 拥有自动定义的 ...
- MySQL中INDEX,PRIMARY,UNIQUE,FULLTEXT之间的区别?
创建MySQL表时,PRIMARY,UNIQUE,INDEX和FULLTEXT有什么区别? 我将如何使用它们? #1楼 我觉得这已经很好地涵盖了,也许除了以下几点: 如果选择性足够,简单的KEY / ...
- 357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits Given a non-negative integer n, count all numbers with unique ...
- Mysql中的count()与sum()区别
Mysql中的count()与sum()区别 首先创建个表说明问题 CREATE TABLE `result` ( `name` varchar(20) default NULL, `subject` ...
- leetcode 330. Patching Array | 1798. Maximum Number of Consecutive Values You Can Make
1798. Maximum Number of Consecutive Values You Can Make | 1798. 你能构造出连续值的最大数目 https://leetcode.com/p ...
- mysql 聚集函数 count 使用详解
mysql 聚集函数 count 使用详解 本文将探讨以下问题 1.count(*) . count(n).count(null)与count(fieldName) 2.distinct 与 coun ...
最新文章
- Configure Drill
- UIButton 详解
- Web-HTML特殊符号的表示
- ubuntu在VMware虚拟机安装了后桌面显示问题
- webservice传递特殊字符时的解决的方法
- 【渗透测试】—如何利用文件包含的方式进行攻击
- java代码-----逻辑运算符
- 小程序对实体行业转型有何影响?
- 基于Web的svg编辑器(2)——层次结构设计(DOM结构)
- UTM坐标和WGS84坐标(如何转换?)
- PDMS.NET开发
- 苹果企业级开发者账号申请详解
- ReactNative实现仿微信或者通讯录快速索引功能
- 什么是面向对象的编程
- 2D 到 3D 的跨越,探索最佳 AR 交互设计之道
- 目前住院病人主要由护士护理,这样不仅需要大量护士,而且由于不能随时观察病人的病情变化,还可能会延误抢救时机。某医院打算开发一个以计算机为中心的监护系统,写出问题定义和分析系统可行性(软件工程导论)
- LeetCode每日一题--有序队列(整理最小表示法)
- 2021年8月世界编程语言排行
- 全速pdf转换成html转换器v1.0官方版
- 200亿元输血求生,中芯国际希望几何?
热门文章
- 程序无法启动ALL_BUILD 拒绝访问
- 2021牛客暑期多校训练营6 :D Gambling Monster 期望dp + fwt + cdq分治
- CF 1475 D. Cleaning the Phone 思维模型
- LCS(2021牛客多校4)
- 牛客网 【每日一题】5月13日 加分二叉树
- CF788789(div1div2)
- Loj#3077-「2019 集训队互测 Day 4」绝目编诗【结论,虚树,鸽笼原理】
- YbtOJ#943-平方约数【莫比乌斯反演,平衡规划】
- P4899-[IOI2018]werewolf 狼人【Kruskal重构树,主席树】
- SP1811-Longest Common Substring【SAM】