Rumah > Soal Jawab > teks badan
输入命令: SELECT a.goods_id,a.goods_name FROM tdb_goods AS a LEFT JOIN (SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING COUNT(goods_name)>1) AS b ON a.goods_name = b.goods_name ;
显示的是tdb_goods 的所有选项
但是在后面加上WHERE a.goods_id > b.goods_id,就只显示两条结果
命令:SELECT a.goods_id,a.goods_name FROM tdb_goods AS a LEFT JOIN (SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING COUNT(goods_name)>1) AS b ON a.goods_name = b.goods_name WHERE a.goods_id > b.goods_id;
结果:
+----------+-------------------------+
| goods_id | goods_name |
+----------+-------------------------+
| 26 | HMZ-T3W 头戴显示设备
| 27 | 玄龙精英版 笔记本散热器
+----------+-------------------------+
2 rows in set (0.00 sec)
前后只是差了一个条件,如果把LEFT JION 改成RIGHT JION 或者 INNER JION 我都可以理解,就是LEFT JION 不明白,求各位大神指点迷津。
数据分析师2017-09-30 23:29:22
Masalah pemadaman berbilang jadual-Soal Jawab laman web PHP Cina-Masalah pemadaman jadual berbilang-Soal Jawab laman web PHP Cina
Lihat sekeliling dan pelajari.
巴扎黑2016-12-21 18:01:53
因为where相当于对链接后的呈现的表再进行了一步操作:条件就是只展示a.goods_id>b.goods_id。根据子查询生成的b表本身只有两条数据(这两条数据本身就是tdb_goods中的重复数据,a中一定也存在而且一共为4条),其中符合进一步筛选条件的只有两条。