文章详情页
mysql在限制条件下筛选某列数据相同的值
浏览:213日期:2022-06-14 09:21:45
问题描述
有一个schema如下
fish(name,species,tankid)eat(species1,species2)
其中eat表示鱼类之间相互捕食关系,species1是被捕食的鱼类tankid表示鱼缸id
需要筛选出:与可以捕食他的鱼(species2)放在同一个鱼缸中(tankid相等)的鱼(species1)的名字
求用sql语句说明
问题解答
回答1:SELECT a.*, b.name AS name1, c.name AS name2FROM eat AS a LEFT JOIN fish AS b ON a.species1=b.speciesLEFT JOIN fish AS c ON a.species2=c.speciesWHERE b.tankid=c.tankid
相关文章:
1. javascript - vue组件通过eventBus通信时,报错a.$on is not a function2. python3.x - python3.5.2安装时make报错求助3. html - vue项目中用到了elementUI问题4. javascript - 在使用 vue.js element ui的时候 怎么样保留table翻页后check的值?5. mysql_replication - mysql读写分离时如果单台写库也无法满足性能怎么解决6. angular.js - 如何控制ngrepeat输出的个数7. ionic 项目 ionic build android -release 打包时报错8. mac里的docker如何命令行开启呢?9. python - 如何用pandas处理分钟数据变成小时线?10. 为什么学习PHP
排行榜

网公网安备