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.
我有两个表,TableA 和 TableB。我需要根据 where 条件从 TableA 中选择一个计数值。我需要从 TableB 中选择两个值。我想要一个结果集中的所有值。结果集中永远不会超过一行。
这是我现在拥有的:
SELECT count(id) FROM TableA WHERE ($some_where_statement) SELECT owner, owner_ID from TableB
我知道这应该很简单,但这会引发错误。有什么建议么?
您可以交叉连接以连接两个不相关表中的行:
SELECT T1.cnt, T2.owner, T2.owner_ID FROM (SELECT count(id) FROM TableA WHERE ($some_where_statement)) AS T1 CROSS JOIN (SELECT owner, owner_ID from TableB) AS T2
要在结果集中只有一行,假设两个子查询都只返回一行。我怀疑第二个子查询不是这种情况。您可能缺少 where 子句。