我有一个包含三个具有以下结构的表的方案
donuts (name: string, price: integer)
grocery (no: string, gname: string, minCredit: integer)
distributor (dname: string, gno: string, deliverydate: date)
distributor.dname和distributor.gno是引用甜甜圈和杂货的外键,哪些键是名称而且没有相应的我在遇到2个查询时遇到问题我想写:
查询名为“Jelly”的杂货店甜甜圈中具有最高minCredit要求的杂货(杂货店,编号:字符串)的数量
SELECT g.no
FROM grocery g, distributor dd, donut d
WHERE minCredit >= * AND d.name = "JELLY"
这不起作用
查询每个甜甜圈共享的杂货编号(杂货店,编号:字符串)以及价格高于2的查询
我试过
SELECT g.no
FROM grocery g, distributor dd, donut d
WHERE g.price >= 2
这也不是正确的事情。任何帮助表示赞赏
答案 0 :(得分:0)
尝试:
1
SELECT g.no
FROM grocery g, distributor dd, donut d
WHERE g.no = dd.gno
AND d.name = dd.dname
AND d.name = 'JELLY'
ORDER BY g.minCredit DESC LIMIT 1
2
SELECT g.no
FROM grocery g, distributor dd, donut d
WHERE g.no = dd.gno
AND d.name = dd.dname
AND d.price >= 2