dongzai3139 2013-05-06 14:50
浏览 15
已采纳

具有多个选择的SQL查询[关闭]

Here's what I have so far:

enter image description here

//Insert a CD supplied by a particular supplier and produced by a particular producer 
Mysqli_query($con, "INSERT INTO CD WHERE suppliername = "Sony" AND producername = "Gold Records" (CD name, CD type, CD year) 
VALUES ('CDname', 'CDtype', 'CDyear')");

//List producers information who produce CD of a particular artist released in a particular year 
mysqli_query($con, "SELECT name from producers WHERE CD artist="Yoko Kano" AND year= "1999");

OR Should I include WHERE artist from song="Yoko Kano" AND year from song= "1999" ?

Is this the correct syntax? Just want to double check.

  • 写回答

1条回答 默认 最新

  • dp13668681869 2013-05-06 15:04
    关注

    To insert a CD, you should be able to use something like:

    INSERT INTO cd (suppliername, producername, title, type, year) 
    VALUES ('Sony', 'Gold Records', 'My CD Title', 'My CD Type', 2008)
    

    I'm not going to give you a full answer to your second question since I'm assuming this is homework. I will give you some guidance though.

    First, if you want a list of producers, you will need to do

    SELECT * FROM producer
    

    But you don't want every producer, you only want the ones that produced CDs released in 1999. How can you get a list fo those CDs? With another query:

    SELECT * FROM cd WHERE year = 1999
    

    So how do you combine these? With something like:

    SELECT * FROM producer, cd where cd.producername = producer.name and cd.year = 1999

    The query that you need is more complex, you need to include the fact that the artist is Yoko Ono but the artist is not in the Cd table, it's in the Song table. That means that you need another join with the Song table. To give you another clue, consider the question, how do I see all Cds released by a particular artist? If you want to see all songs by a particular artist, that's easy:

    SELECT * FROM Song WHERE artist = 'Yoko Ono'
    

    What about the Cds? You could do:

    SELECT * FROM Cd, Song WHERE Song.CdTitle = Cd.Title
    

    Your final query will need to select from all three tables and you'll need all of the constraints to be in place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看