sql - 如何在SQL中添加统计值

标签 sql

现在我的数据表就像

uid mid  ..
1   xx   ..
2   xx   ..
-   a    ..
-   b    ..
...

我写了两个 SQL 查询:
select count(distinct uid) from T where uid!='-'select count(distinc mid) from T where uid='-' ,

现在我只想在一个 SQL 查询中获得这两个值的总和。有人有任何想法可以帮助我吗?

最佳答案

试试这个查询

select count(distinct uid) from T where uid!='-'
union all
select count(distinc mid) from T where uid='-'

关于sql - 如何在SQL中添加统计值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31108149/

相关文章:

mysql - SQLAlchemy:如何在一个事务中交换唯一值?

sql - Excel 到具有较大数据集(>2000 条记录)的远程 oracle 数据库。使用支持 FetchSize 的驱动程序存储 proc 调用

MySQL基于正则表达式的select

MySQL ORDER BY 从头到尾发送

java - Java.sql 的 getRow() 线程安全吗?

sql - 如何将时间戳插入postgreSQL数据库

java - Hibernate:通过单个连接表引用多个表

mysql - 将几何图形从 MSSQL 导入 MySQL(线串)

mysql - 填写数据和缺失日期

sql - 如何选择小于30的数字总和和大于30的数字总和?