我遇到的问题是我几天都没有解决。
我有3张桌子。
表"经销商"
ID | Distributor
1 | Distributor A
2 | Distributor B
3 | Distributor C
表"产品":
ID | Product
1 | Apple
2 | Peache
3 | Banana
4 | Lemon
表" DistributorProduct" - 哪个经销商可以提供哪种产品。
ID | DistributorID | ProductID
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 1 | 4
5 | 2 | 1
6 | 2 | 3
7 | 2 | 4
7 | 3 | 3
7 | 4 | 4
现在我想让所有可以提供Apple和Banana的经销商。 (结果必须是经销商A和经销商B)。
我该怎么做?什么是SQL语句?
非常感谢您的帮助。
迪特尔
答案 0 :(得分:0)
$(document).ready(function() {
var savesnotesbtn = document.getElementById("savenotesbtn");
var addnotebtn = document.getElementById("addNoteBtn");
var noteCount = localStorage.getItem("noteCount");
if (noteCount === null) {
noteCount = 0;
}
addnotebtn.addEventListener("click", addNotes);
//ADD NOTES
function addNotes() {
noteCount++;
var note = $("#noteInput").val();
console.log("Note: " + note);
console.log("Note Count: " + noteCount);
var display = document.createElement("div");
document.getElementById("displayContainer").appendChild(display);
display.className = "noteDisplay";
display.id = "note" + noteCount;
$("#note" + noteCount).text(note);
localStorage.setItem("noteCount", noteCount);
}
});
如果某些连接表达式错误,那么您可以不加入连接。
select d.*
from Distributor d
left join DistributorProducts dp on dp.DistributorId = d.id
left join Product p on p.Id = dp.ProductId and p.product = 'Apple' and
p.product = 'Banana'
我相信这应该有用。
答案 1 :(得分:0)
这应该有效:
select Distributor.ID, Distributor.Name
from Distributor, Product Apple, Product Banana, DistributorProduct
where
DistributorProduct.DistributorID = Distributor.ID and
DistributorProduct.ProductID = Apple.ID and
Apple.Name = 'Apple' and
DistributorProduct.ProductID = Banana.ID and
Banana.Name = 'Banana'
group by Distributor.ID