mysql - sql 跨表基础查询问题(附带table图片)
PHPz
PHPz 2017-04-17 13:02:56
0
3
1669

首先附上两张表:
product 表

quotation 表

问题

检索对飞利浦的所有型号都有报价的经销商

请问如何能只使用sql语句查询出想要的结果。

如果是写php程序

我的思路是

查询出product所有飞利浦的型号

存入数组

然后将出quotation中 每个经销商对飞利浦有报价的型号与数组中一一对比,完全匹配的话,则提取出经销商来。

PHPz
PHPz

学习是最好的投资!

reply all(3)
phpcn_u29672

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)

荒原

Isn’t it just a join table query?>?

Ty80
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template