子查询是否可以返回两个值?

2022-01-23 00:00:00 sql subquery mysql mysql-error-1241

子查询是否可以将两个值返回到外部查询?如:

Is it possible for a subquery to return two values onto the outer query? Such as:

SELECT 1, 
       (SELECT COUNT(*), MAX(*) FROM test_table WHERE test=123) 
FROM another_table

或者有更好的方法吗?

推荐答案

如果你在FROM子句中使用子查询而不是字段列表,那么你可以把输出当作一个表来引用到单独的列.

If you use the subquery in the FROM clause rather than the field list, then you can treat the output as a table and refer to the separate columns.

相关文章