mysql - 在多个表sql中的同一列上选择不同的

标签 mysql sql-server

这里是 SQL 新手。

我有这个架构:

where nodes table and ways table have the same column uid

我需要简单的英语是:

“在 2 列中,将一列放在另一列上方,然后计算有多少个不同值”

我已经尝试过

SELECT COUNT (DISTINCT uid ) from nodes  UNION SELECT COUNT (DISTINCT uid) from ways ;

SELECT   distinct nodes.uid  from nodes  JOIN ways on nodes.uid = ways.uid ;

sqlite> SELECT COUNT (DISTINCT uid ) from nodes  UNION SELECT COUNT (DISTINCT uid) from ways ;
1195
2182
sqlite> SELECT   uid  from nodes  FULL OUTER JOIN ways on nodes.uid = ways.iud ;
Error: RIGHT and FULL OUTER JOINs are not currently supported

SELECT COUNT (DISTINCT iud) FROM (SELECT DISTINCT uid from nodes as uid UNION SELECT DISTINCT uid from ways as uid as subq);

SELECT   count (distinct nodes.uid)  from nodes  JOIN ways on nodes.uid = ways.uid ;

需要很长时间,我不确定nodes.uid =ways.uid是正确的方法

有什么想法吗?

最佳答案

我想我明白了

SELECT COUNT (DISTINCT uid) from (SELECT DISTINCT uid  from nodes  UNION SELECT  DISTINCT uid from ways) as subq ;

关于mysql - 在多个表sql中的同一列上选择不同的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40900230/

相关文章:

php - 由于字符串中存在逗号,使用 PHP 导入 CSV 时出现问题

PHP 将 Unix 时间转换为 ISO 并减去一个小时

mysql - Codeigniter-Style Mysql 在 IE 8 上不会产生任何结果

sql - 如何在 PIVOT SQL 查询的日期过滤器之间添加

SQL 服务器 : is it possible to get data from another SQL server without setting linked server?

sql-server - 如何在sql server 2008中获取特定值的列名

mysql - Memory_used 是否以字节为单位?

mysql - 为什么这个带有子查询的 SQL 查询非常慢?

sql-server - 执行查询限制

c# - MSSQL中子字符串的更新操作