Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查找相同的表行_Php_Mysql_Sql - Fatal编程技术网

Php 查找相同的表行

Php 查找相同的表行,php,mysql,sql,Php,Mysql,Sql,在买桌上。当客户购买同一本书时,将1行添加到表中。因此,当在购买页面中看到购买列表时,它是这样的: buy1 price1 downloadlink1 buy1 price1 downloadlink1 buy1 price1 downloadlink1 buy2 price2 downloadlink2 buy2 price2 downloadlink2 buy2 price2 downloadlink2 但我想在同一行价格和下载链接删除,只有第一行显示这个值 像这样: buy1 price

在买桌上。当客户购买同一本书时,将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查询???

在执行下载链接时在sql查询中使用distinct

在执行下载链接时在sql查询中使用distinct

如果特定项不是由该用户添加的,则向表中添加行 坐到桌子上

如果该项目已经存在,请使用项目id和用户id检查并更新 桌子

如果特定项不是由该用户添加的,则向表中添加行 坐到桌子上

如果该项目已经存在,请使用项目id和用户id检查并更新 桌子


好吧,如果是MS SQL server,我可以建议使用上面的行数 但在你的情况下,我可以建议你试试这个,我想你桌上有一些身份证

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

好吧,如果是MS SQL server,我可以建议使用上面的行数 但在你的情况下,我可以建议你试试这个,我想你桌上有一些身份证

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


请发布您拥有的表格类型,用户是否可以反复购买同一本书?是的,每个用户都可以购买同一本书,因为每本书只在一个pcI中工作。我不明白您到底想做什么?为什么要买两行空白?空白行对数据没有意义…请发布您拥有的表格类型,用户是否可以反复购买同一本书?是的,每个用户都可以购买同一本书,因为每本书只在一个pcI中工作。我不明白您到底在做什么?为什么要买两行空白?空行对数据没有意义…我如何使用它?你能给我一个例子吗?我使用这个//mysql\u querySELECT DISTINCT*FROM buy WHERE user='$userf'和active='1'订单,按sub或diemsql\u错误//但not WORKSTINCT将给出一行共两行,一行用于buy1,另一行用于buy2,但OP不需要两行。OP想要全部6行都回来…我怎么用这个?你能给我一个例子吗?我使用这个//mysql\u querySELECT DISTINCT*FROM buy WHERE user='$userf'和active='1'订单,按sub或diemsql\u错误//但not WORKSTINCT将给出一行共两行,一行用于buy1,另一行用于buy2,但OP不需要两行。OP希望所有6行都返回…我使用mysql服务器。此代码可以工作,但我不知道如何将此代码更改为mysql。mysql_querySELECT DISTINCT*FROM buy WHERE user='$userf'和active='1'ORDER BY sub或diemysql_error//表中有'id'auto。这意味着我必须将valuei与valuei-1进行比较?如果您发布了表模式,我可以发布您真正的查询表buy id、user、versionid、sub、hard、active、res//在第一行中,我想显示所有内容,但在第二行或更多行中,我只想在页面中显示sub值。让我们使用mysql服务器。此代码可以工作,但我不知道如何将此代码更改为mysql。mysql_querySELECT DISTINCT*FROM buy WHERE user='$userf'和active='1'ORDER BY sub或diemysql_error//表中有'id'auto。这意味着我必须将valuei与valuei-1进行比较?如果您发布表模式,我可以发布您真正的查询表buy id、user、versionid、sub、hard、active、res//在第一行中,我希望显示所有内容,但在第二行或更多行中,我只希望在页面中显示sub值。让我们