dqlb38410 2010-11-10 13:10
浏览 29

具有3个表的复杂mysql查询

now i have three tables ok?

  1. catgories | cat_id
  2. areas | area_id
  3. ads | cat_id - area_id

now i want get the the areas under the catgories with contain the ads this mean - catgorty -- area contant catgorty ads example i have cars as a catgory and egypt as area and a car for sale as ads now i want show the areas under the catgories which contain ads this mean i have egypt usa canda and one ads in egypt now i want show it like cars -- egypt and if i have one more ad in the usa it appear cars --egypt --usa this mean give me the areas with contain ads under that catgory

  • 写回答

2条回答 默认 最新

  • dsqe46004 2010-11-10 13:43
    关注

    countries with adds:

    SELECT *
      FROM areas
     WHERE area_id in (SELECT area_id FROM ads) 
    

    countries with adds for cars:

    SELECT *
      FROM areas
     WHERE area_id in (
        SELECT ads.area_id
          FROM ads,categories
         WHERE ads.cat_id = categories.cat_id
           AND categories.cat_name = 'cars') 
    

    is that what you meant?

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教