gpt4 book ai didi

php - 查找相同的表行

转载 作者:行者123 更新时间:2023-11-29 00:37:41 25 4
gpt4 key购买 nike

在购买表中。当客户购买同一本书时,将 1 行添加到表中。所以当在购买页面看到购买列表时,它是这样的:

buy1 price1 downloadlink1
buy1 price1 downloadlink1
buy1 price1 downloadlink1
buy2 price2 downloadlink2
buy2 price2 downloadlink2
buy2 price2 downloadlink2

但我想在同一行删除价格和下载链接,并且只有第一行显示此值像这样:

buy1 price1 downloadlink1
buy1
buy1
buy2 price2 downloadlink2
buy2
buy2

如何使用sql查询???

最佳答案

好吧,如果它是 MS SQL 服务器,我可以建议使用 row_number over()但在你的情况下,我建议你试试这个(我想你的表中有一些 id)

select
A.sub,
case when A.frst = 1 then A.user else null end as user,
case when A.frst = 1 then A.versionid else null end as versionid,
case when A.frst = 1 then A.hard else null end as hard,
case when A.frst = 1 then A.active else null end as active,
case when A.frst = 1 then A.res else null end as res
from
(
select
*,
case
when exists
(
select *
from buy as tt
where
tt.sub = t.sub and tt.res = t.res and
tt.user = t.user and tt.versionid = t.versionid and
tt.hard = t.hard and tt.active = t.active and
tt.id < t.id
) then 0
else 1
end as frst
from buy as t
) as A
order by A.sub, A.frst desc

SQL FIDDLE

关于php - 查找相同的表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13600655/

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