Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SQL中有一种标准方法可以将许多行加入到一个表中,也接受0?这是一个例子:
SELECT t1.id, COUNT(t2.*) FROM t1 LEFT OUTER JOIN t2 ON ( t1.id = t2.id ) GROUP BY t1.id
我需要一个替代方案,因为我将 odbc 与不同的数据库一起使用,并且在某些数据库上不支持左连接。
SELECT t1.id, (SELECT COUNT(*) FROM t2 WHERE t2.id = t1.id) as t2_count FROM t1
两个选项: 选项 1:使用 (+) 运算符:
SELECT t1.id, COUNT(t2.*) FROM t1, t2 WHERE t2.id(+) = t1.id GROUP BY t1.id
我不知道它是否适用于所有驱动程序。适用于所有驱动程序的选项 2 是创建视图并改为创建视图。