在多表sql中选择相同列的区别

时间:2016-11-30 23:38:40

标签: 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是正确的方法

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

我想我明白了

var dogData = {breeds: [{Dog: "Golden Retriever"}, "Rottweiler"]}

答案 1 :(得分:0)

由于UNION返回一组不同的连接表,因此您不需要使用DISTINCT关键字

SELECT COUNT(uid) Cnt
FROM   (
    SELECT uid 
    FROM   nodes
    UNION 
    SELECT uid
    FROM   ways
) t