Home  >  Q&A  >  body text

mysql - sql 跨表基础查询问题(附带table图片)

首先附上两张表:
product 表

quotation 表

问题

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

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

如果是写php程序

我的思路是

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

存入数组

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

PHPzPHPz2716 days ago1591

reply all(3)I'll reply

  • phpcn_u29672

    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)

    reply
    0
  • 荒原

    荒原2017-07-10 17:14:46

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

    reply
    0
  • PHP中文网

    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
    

    reply
    0
  • Cancelreply