解决当distinct和join同时存在distinct失效问题
$sql = 'select distinct(ontopid),gb.id as id,f.id as fid,g.id as gid,g.*,gb.*,f.* from pk_groupbuy gb
left join pk_ontop as o on o.ontopid=gb.id
left join pk_goods g on gb.goodsid=g.id and g.status=2 and g.invalid>UNIX_TIMESTAMP()
left join pk_fastgroupbuy f on gb.fastgroupbuyid=f.id
where gb.id in ('.$arr_str.') and (gb.status="2" or gb.status="3")
and gb.endtime>UNIX_TIMESTAMP() and gb.starttime group by onid limit $start,$num"; return TableSystem::query($sql); 变量说明:$arr_str是一个由pk_groupbuy中主键 id组成的一个数组,经过explode函数得到的字符串, $start,$num分别是查询的开始记录数,和要查询的记录数。 问题说明:pk_ontop表中ontopid在不能记录中有重复现象 比如:我只需要查询出来pk_ontop中当天置顶的ontopid,即商品id,不需要其他的商品信息,查询出来的有ontopid就算有重复现象,这时我可以通过去除数组重复元素解决问题,但是如果我要查询出相应商品id并查询其他相关联表中的信息,并按照ontop表中starttime,status,paixu字段进行排序等操作时,就需要join pk_ontop表,所以之前解决的重复问题就又会出现,无法处理,特别是在api中,是不允许出现重复的,这要怎么办呢?我也不会额,别人教我这样弄,请大家参考下: $sql = 'SELECT DISTINCT(ontopid),starttime,paixu FROM pk_ontop ORDER BY starttime DESC,STATUS ASC,paixu ASC LIMIT 17'; $sql = 'select gb.local,f.phone,f.shopname as fshopname,gb.maxnum,gb.intro,gb.buynum,g.pic,f.googleaddress,gb.goodsclassid,gb.sellerid,f.img,gb.province,gb.city,gb.id,gb.title,g.pic,gb.starttime,
$arr = TableSystem::query($sql);
foreach($arr as $key=>$val){
$topids[$key] = $val['ontopid'];
}
$arr_str = implode(',',$topids);
$arr1 = TableSystem::query($sql);
gb.endtime,gb.price,gb.goodsprice from pk_groupbuy gb
left join pk_goods g on gb.goodsid=g.id and g.status=2 and g.invalid > UNIX_TIMESTAMP()
left JOIN pk_fastgroupbuy f ON f.id=gb.fastgroupbuyid
where (gb.status="2" or gb.status="3") and gb.endtime > UNIX_TIMESTAMP()
and gb.starttime
$arr2 = TableSystem::query($sql);
foreach($arr2 as $key=>$val){
$local[$val['id']] = $val['local'];
$phone[$val['id']] = $val['phone'];
$fshopname[$val['id']] = $val['fshopname'];
$maxnum[$val['id']] = $val['maxnum'];
$intro[$val['id']] = $val['intro'];
$buynums[$val['id']] = $val['buynum'];
$fgoogleaddresss[$val['id']] = $val['googleaddress'];
$goodsclassid[$val['id']] = $val['goodsclassid'];
$sellids[$val['id']] = $val['sellerid'];
$provices[$val['id']] = $val['province'];
$citys[$val['id']] = $val['city'];
$titles[$val['id']]= $val['title'];
$pics[$val['id']] = $val['pic'] ? $val['pic'] : $val['img'];
$starttimes[$val['id']] = $val['starttime'];
$endtimes[$val['id']] = $val['endtime'];
$prices[$val['id']] = $val['price'];
$goodsprices[$val['id']] = $val['goodsprice'];
}
unset($arr2);
foreach($arr1 as $key=>$val){
$list[$key]['id'] = $val['ontopid'];
$list[$key]['province'] = $provices[$val['ontopid']];
$list[$key]['city'] = $citys[$val['ontopid']];
$list[$key]['title'] = $titles[$val['ontopid']];
$list[$key]['pic'] = $pics[$val['ontopid']];
$list[$key]['starttime'] = $starttimes[$val['ontopid']];
$list[$key]['endtime'] = $endtimes[$val['ontopid']];
$list[$key]['price'] = $prices[$val['ontopid']];
$list[$key]['goodsprice'] = $goodsprices[$val['ontopid']];
$list[$key]['sellerid'] = $sellids[$val['ontopid']];
$list[$key]['fgoogleaddress'] = $fgoogleaddresss[$val['ontopid']];
$list[$key]['goodsclassid'] = $goodsclassid[$val['ontopid']];
$list[$key]['buynum'] = $buynums[$val['ontopid']];
$list[$key]['intro'] = $intro[$val['ontopid']];
$list[$key]['maxnum'] = $maxnum[$val['ontopid']];
$list[$key]['fshopname'] = $fshopname[$val['ontopid']];
$list[$key]['fphone'] = $phone[$val['ontopid']];
$list[$key]['local'] = $local[$val['ontopid']];
}
return $list;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Solution to the problem that Win11 system cannot install Chinese language pack With the launch of Windows 11 system, many users began to upgrade their operating system to experience new functions and interfaces. However, some users found that they were unable to install the Chinese language pack after upgrading, which troubled their experience. In this article, we will discuss the reasons why Win11 system cannot install the Chinese language pack and provide some solutions to help users solve this problem. Cause Analysis First, let us analyze the inability of Win11 system to

As smartphone technology continues to develop, mobile phones play an increasingly important role in our daily lives. As a flagship phone focusing on gaming performance, the Black Shark phone is highly favored by players. However, sometimes we also face the situation that the Black Shark phone cannot be turned on. At this time, we need to take some measures to solve this problem. Next, let us share five tips to teach you how to solve the problem of Black Shark phone not turning on: Step 1: Check the battery power. First, make sure your Black Shark phone has enough power. It may be because the phone battery is exhausted

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Everyone knows that if the computer cannot load the driver, the device may not work properly or interact with the computer correctly. So how do we solve the problem when a prompt box pops up on the computer that the driver cannot be loaded on this device? The editor below will teach you two ways to easily solve the problem. Unable to load the driver on this device Solution 1. Search for "Kernel Isolation" in the Start menu. 2. Turn off Memory Integrity, and it will prompt "Memory Integrity has been turned off. Your device may be vulnerable." Click behind to ignore it, and it will not affect the use. 3. The problem can be solved after restarting the machine.

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

Title: Analysis of Oracle Error 3114: Causes and Solutions When using Oracle database, you often encounter various error codes, among which error 3114 is a relatively common one. This error generally involves database link problems, which may cause exceptions when accessing the database. This article will interpret Oracle error 3114, discuss its causes, and give specific methods to solve the error and related code examples. 1. Definition of error 3114 Oracle error 3114 pass
