我有2个表 - 产品和发票
Invoice表具有此结构
invoiceId
productId
invoiceType
invoiceType具有以下值:
如何选择产品表中仅包含'形式表'的产品? Invoice表中的InvoiceType列中的值,而不是其他两个(avans,final)?
答案 0 :(得分:1)
一种方法使用exists
和not exists
:
select p.*
from products p
where exists (select 1
from invoices i
where i.productid = p.productid and i.invoicetype = 'proforma'
) and
not exists (select 1
from invoices i
where i.productid = p.productid and i.invoicetype <> 'proforma'
)
答案 1 :(得分:0)
Select * from products p
where Exists
(Select * from Invoices
Where productId = p.productId
and invoiceType = 'proforma')
and Not Exists
(Select * from Invoices
Where productId = p.productId
and invoiceType in ('avans', 'final'))
答案 2 :(得分:0)
试试这个
SELECT * FROM Products LEFT JOIN Invoices ON Products.productid = Invoices.productid AND
Invoices.InvoiceType = 'proforma'
答案 3 :(得分:0)
你的sql应该如下所示,不知道确切的字段名称这是我能做的最好的:
从发票中选择* products.productid = invoices.productid上的内部联接产品 invoices.invoicetype ='proforma'
答案 4 :(得分:0)
这应该是数据库的1次完整扫描:
document.querySelector('.myForm').addEventListener('submit', function(e) {
e.preventDefault();
// do your put request here
}