簡體   English   中英

僅保留 SQL 中的行,其中 columnA 中的值大於 columnA 中的值,並且 columnB 中的值等於 x 沒有嵌套問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM