gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 19:47:44 25 4
gpt4 key购买 nike

这里是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com