![](/img/trans.png)
[英]SQL How to select columnA and columnB where columnB has a distinct value
[英]Only keep rows in SQL where the value in columnA is bigger than the value in columnA and the value in columnB is equal to x without a nested question
我的數據庫:
+----------+-------------------+--------+--------+------+
| pk_parts | name | color | weight | qoh |
+----------+-------------------+--------+--------+------+
| 1 | central processor | pink | 10 | 1 |
| 2 | memory | gray | 20 | 32 |
| 3 | disk drive | black | 685 | 2 |
| 4 | tape drive | black | 450 | 4 |
| 5 | tapes | gray | 1 | 250 |
| 6 | line printer | yellow | 578 | 3 |
| 7 | l-p paper | white | 15 | 95 |
| 8 | terminals | blue | 19 | 15 |
| 9 | terminal paper | white | 2 | 350 |
| 10 | byte-soap | clear | 0 | 143 |
| 11 | card reader | gray | 327 | 0 |
| 12 | card punch | gray | 427 | 0 |
| 13 | paper tape reader | black | 107 | 0 |
| 14 | paper tape punch | black | 147 | 0 |
+----------+-------------------+--------+--------+------+
我需要獲得比讀卡器權重更高的行的名稱+顏色,我不能使用嵌套問題。
SELECT t1.*
FROM parts t1
JOIN parts t2 ON t1.weight > t2.weight
WHERE t2.name='card reader';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.