有一个schema如下
fish(name,species,tankid) eat(species1,species2)
其中eat表示鱼类之间相互捕食关系,species1是被捕食的鱼类tankid表示鱼缸id
需要筛选出:与可以捕食他的鱼(species2)放在同一个鱼缸中(tankid相等)的鱼(species1)的名字
求用sql语句说明
数据分析师2017-10-01 01:07:01
Mysql filters the same values in a column of data under restricted conditions? -PHP Chinese website Q&A-Mysql filters the same values in a column of data under restricted conditions? -PHP Chinese website Q&A
Let’s take a look and learn.
迷茫2017-03-23 09:18:36
SELECT a.*, b.name AS name1, c.name AS name2 FROM eat AS a LEFT JOIN fish AS b ON a.species1=b.species LEFT JOIN fish AS c ON a.species2=c.species WHERE b.tankid=c.tankid