gpt4 book ai didi

sql - 如何跳过子查询的匹配结果?

转载 作者:行者123 更新时间:2023-12-03 17:17:15 24 4
gpt4 key购买 nike

使用sqlite3,我有一个看起来像这样的表:

+---------+-----------------+----------+-----------+--------+
| ArtId | Location | ArtistID | Title | Size |
+---------+-----------------+----------+-----------+--------+
| 3 | China | 400 | birds | small |
| 4 | Samoa | 670 | stars | large |
| 5 | Chile | 427 | clouds | medium |
| 6 | US | 427 | clouds | small |
| 7 | France | 123 | collage | small |
| 8 | Spain | 123 | collage | large |
| 9 | Belarus | 123 | collage | medium |
+---------+-----------------+----------+-----------+--------+


我有一个查询,生成所有结果,其中唯一的结果是标题和艺术家重复的结果:

SELECT * 
FROM LiveArt c1, (SELECT Title, ArtistID FROM LiveArt GROUP BY Title, ArtistID) c2
WHERE c1.Title = c2.Title AND c1.ArtistID = c2.ArtistID


产生下表:

+---------+-----------------+----------+-----------+--------+
| ArtId | Location | ArtistID | Title | Size |
+---------+-----------------+----------+-----------+--------+
| 5 | Chile | 427 | clouds | medium |
| 6 | US | 427 | clouds | small |
| 7 | France | 123 | collage | small |
| 8 | Spain | 123 | collage | large |
| 9 | Belarus | 123 | collage | medium |
+---------+-----------------+----------+-----------+--------+


我要退货的是这样的:

+---------+-----------------+----------+-----------+--------+
| ArtId | Location | ArtistID | Title | Size |
+---------+-----------------+----------+-----------+--------+
| 6 | US | 427 | clouds | small |
| 8 | Spain | 123 | collage | large |
| 9 | Belarus | 123 | collage | medium |
+---------+-----------------+----------+-----------+--------+


如何调整查询以执行此操作(跳过第一个匹配的结果)?

最佳答案

select * from tabName A
where A.ArtId !=
(
select min(ArtId)
from tabName B
group by Title
having A.Title=B.Title
);




ArtId       Location    ArtistID    Title       Size
---------- ---------- ---------- ---------- ----------
6 US 427 clouds small
8 Spain 123 collage large
9 Belarus 123 collage medium

关于sql - 如何跳过子查询的匹配结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com