在不使用连接的情况下,在另一列的计数大于 1 时显示列
Display Columns when count from another column is greater than 1 without using joins
这是一个与作业相关的问题,我不知道如何回答它,因为我不允许使用连接。
我需要
为那些有 2 个或更多发票的车辆显示 Vehicle 中的所有列。
我遇到的问题是在不使用联接的情况下将信息从 Invoice 移至 Vehicle。
目前我有
SELECT Invoice.ivin AS Expr1, Vehicle.vmake, Vehicle.vyear, Vehicle.vcolor, Vehicle.vdcode, Vehicle.vfuel, Vehicle.vcylinders, Vehicle.vweight, Vehicle.vbody
FROM Vehicle INNER JOIN Invoice ON Vehicle.vvin = Invoice.ivin
GROUP BY Invoice.ivin, Vehicle.vmake, Vehicle.vyear, Vehicle.vcolor, Vehicle.vdcode, Vehicle.vfuel, Vehicle.vcylinders, Vehicle.vweight, Vehicle.vbody
HAVING (((Count(*))>1));`
哪个有效,但是不允许我使用内部联接。有什么可能的替代品?
将 EXISTS
与相关子查询一起使用是否符合要求?
select *
from Vehicle v
where exists (select null
from Invoice i
where i.ivin = v.vvin
having count(*) >= 2)
编辑: 也许 Access 真的希望您有一个 group by
以便能够在 [=14] 中使用聚合函数=] 子句。试试这个,看看它是否有效: 我将离开下面的查询,因为它确实有效。但是根据 Gordon Linoff 在下面的评论,我所需要的只是将子查询中的 select *
调整为 select 1
或 select null
之类的其他内容,就像我现在上面的那样。
select *
from Vehicle v
where exists (select i.ivin
from Invoice i
where i.ivin = v.vvin
group by i.ivin
having count(*) >= 2)
这是一个与作业相关的问题,我不知道如何回答它,因为我不允许使用连接。
我需要
为那些有 2 个或更多发票的车辆显示 Vehicle 中的所有列。
我遇到的问题是在不使用联接的情况下将信息从 Invoice 移至 Vehicle。
目前我有
SELECT Invoice.ivin AS Expr1, Vehicle.vmake, Vehicle.vyear, Vehicle.vcolor, Vehicle.vdcode, Vehicle.vfuel, Vehicle.vcylinders, Vehicle.vweight, Vehicle.vbody
FROM Vehicle INNER JOIN Invoice ON Vehicle.vvin = Invoice.ivin
GROUP BY Invoice.ivin, Vehicle.vmake, Vehicle.vyear, Vehicle.vcolor, Vehicle.vdcode, Vehicle.vfuel, Vehicle.vcylinders, Vehicle.vweight, Vehicle.vbody
HAVING (((Count(*))>1));`
哪个有效,但是不允许我使用内部联接。有什么可能的替代品?
将 EXISTS
与相关子查询一起使用是否符合要求?
select *
from Vehicle v
where exists (select null
from Invoice i
where i.ivin = v.vvin
having count(*) >= 2)
编辑: 也许 Access 真的希望您有一个 我将离开下面的查询,因为它确实有效。但是根据 Gordon Linoff 在下面的评论,我所需要的只是将子查询中的 group by
以便能够在 [=14] 中使用聚合函数=] 子句。试试这个,看看它是否有效:select *
调整为 select 1
或 select null
之类的其他内容,就像我现在上面的那样。
select *
from Vehicle v
where exists (select i.ivin
from Invoice i
where i.ivin = v.vvin
group by i.ivin
having count(*) >= 2)