遇到这样的问题——我不能将这两个请求结合起来,怎么办?一张表中的所有数据
SELECT
max(f.price) AS max_rent,
min(f.price) AS min_rent
FROM Commercial f
WHERE f.type = 1;
SELECT
max(f.price) AS max_sale,
min(f.price) AS min_sale
FROM Commercial f
WHERE f.type = 0;
收到结果。2 表与结果
+---------+---------+ +---------+---------+
| max_sale| min_sale| |max_sale | min_sale|
+---------+---------+ +---------+---------+
| 23 | 45 | | 15 | 52 |
+---------+---------+ +---------+---------+
预期结果。1 个结果表
+---------+---------+---------+---------+
| max_sale| min_sale| max_sale| min_sale|
+---------+---------+---------+---------+
| 23 | 45 | 15 | 52 |
+---------+---------+---------+---------+
这对你有用吗?它应该沿着一行返回 4 列:
SELECT
C1.max_rent,
C1.min_rent,
C0.max_rent,
C0.min_rent
FROM
(
SELECT
max(f.price) AS max_rent,
min(f.price) AS min_rent
FROM Commercial f
WHERE f.type = 1) C1,
(
SELECT
max(f.price) AS max_rent,
min(f.price) AS min_rent
FROM Commercial f
WHERE f.type = 0) C0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句