首先附上两张表:
product 表
quotation 表
问题:
检索对飞利浦的所有型号都有报价的经销商
请问如何能只使用sql语句查询出想要的结果。
如果是写php程序
我的思路是
查询出product所有飞利浦的型号
存入数组
然后将出quotation中 每个经销商对飞利浦有报价的型号与数组中一一对比,完全匹配的话,则提取出经销商来。
phpcn_u296722017-09-25 13:41:40
You don’t need to use the product report. You can directly use the quotation table and add Philips with the model number. Of course, if there is no word Philips in the model number, you can use in (subquery to find out the Philips model number)
PHP中文网2017-04-17 13:04:56
SELECT tt.`duler` FROM (
SELECT SUM(t.`type`) AS `count`, t.`duler` FROM ( # duler 是经销商
SELECT q.* FROM quotation q
LEFT JOIN product p
ON q.`type` = q.`type` # type 是型号
WHERE q.`type` LIKE '飞利浦%'
) t
GROUP BY t.`duler`
) tt
WHERE tt.`count` = 6