我正在处理两个 sql 查询,我想将它们合并为一个查询,因此第一个查询的结果将在第一列中,第二个查询的结果将在第二列中。我怎样才能做到这一点?
我试过 union,但它会将结果放在两行中......那不是我想要的......
select count(*) as ColumnA from Inventory i, Sale s where i.vin=s.vin and i.condition='new'
select count(*) as ColumnB from Inventory i, Sale s where i.vin=s.vin and i.condition='used' order by 1 desc;
最佳答案
您可以像这样在一个查询中组合使用两个子查询:
select
(select count(*) from Inventory i, Sale s where i.vin=s.vin and i.condition='new') as New,
(select count(*) from Inventory i, Sale s where i.vin=s.vin and i.condition='used') as Used
您试图通过 order by statement 实现什么目标?
关于sql - 将两个单独查询的结果合并到两列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30987822/