转自:http://blog.csdn.net/helencoder/article/details/50328629

近期项目中,遇到数据表去重要求,对于ThinkPHP的去重有了更加准确的认识和体会。
两种去重方式:

$test_data = M('hot');  //实例化数据表
$data = $test_data->Distinct(true)->field('descriprion')->order('description desc')->select(); //利用distinct方法去重
$data = $test_data->group('description')->order('description desc')->select(); //利用group方法去重
dump($data);

对于两种去重方式:
利用distinct去重、简单易用,但只能对于单一字段去重,并且最终的结果也仅为去重的字段,实际应用价值不是特别大。
利用group去重,最终的显示结果为所有字段,且对单一字段进行了去重操作,效果不错,但最终显示结果除去去重字段外,按照第一个字段进行排序,可能还需要处理。

ThinkPHP去重 distinct和group by的更多相关文章

  1. distinct 与group by 去重

    mysql中常用去重复数据的方法是使用 distinct  或者group by ,以上2种均能实现,但2者也有不同的地方. distinct 特点: 如:select  distinct   nam ...

  2. mysql数据去重复distinct、group by

    使用distinct 和group by都可以实现数据去重. select distinct 字段 group by 一般放在where条件后

  3. 44 答疑(三)--join的写法/Simple nested loop join的性能问题/Distinct和group by的性能/备库自增主键问题

    44 答疑(三) Join的写法 35节介绍了join执行顺序,加了straight_join,两个问题: --1 如果用left join,左边的表一定是驱动表吗 --2 如果两个表的join包含多 ...

  4. 总结distinct、group by 、row_number()over函数用法及区别

    distinct和group by 是一样的,查询去重,只能是全部重复的,也可以理解为针对单例,因为一行有一个字段不一样,他们就会认为这两行内容是不重复的.但是使用row_number()over这个 ...

  5. mysql 查询去重 distinct

    mysql 查询去重 distinct   待完善内容..

  6. MySQL中distinct和group by性能比较[转]

    MySQL中distinct和group by性能比较[转] 之前看了网上的一些测试,感觉不是很准确,今天亲自测试了一番.得出了结论(仅在个人计算机上测试,可能不全面,仅供参考) 测试过程: 准备一张 ...

  7. mysql distinct跟group by性能

    mysql distinct和group by性能   1,测试前的准备 //准备一张测试表 mysql> CREATE TABLE `test_test` ( ->   `id` int ...

  8. (转)数据库 distinct 和 group by 的区别

    这两者本质上应该没有可比性,distinct 取出唯一列,group by 是分组,但有时候在优化的时候,在没有聚合函数的时候,他们查出来的结果也一样. 举例来说可能方便一点. A表 id num a ...

  9. DISTINCT 与 GROUP BY 的比较

    看了很多文章,这两个SQL语句在不同的数据库上面的实现上可能有相同或有不同,但是应当要明确它们在功能概念上的区别,最终得出结论: GROUP BY 用来使用聚集函数获得值,比如 AVG, MAX, M ...

随机推荐

  1. Delphi 精选文章地址

    Delphi 三层开发 ************   http://blog.csdn.net/lailai186/article/category/1396968 Delphi CxGrid 汇总 ...

  2. iOS-UIView 之 layoutMargins & preservesSuperviewLayoutMargins 解惑

    这里先看下苹果给出的解释: iOS8.0之后,uiview默认layoutMargins 为(8,8,8,8),也可以自己指定,仅适用于自动布局:当添加子view到父view上时,这样设置好约束 默认 ...

  3. vs2013显示行号

    随便打开一个项目,可以看到代码框内并没有显示行号 选择“工具”-“选项”,打开后界面如下 选择文本编辑器,找到下图中的“行号”并勾选 行号可以显示了 5 这样我们就完成了任务

  4. ExpandableListView的用法

    ExpandableListView组件是android中一个比较常用的组件,当点击一个父item的时候可以将它的子item显示出来,像手机QQ中的好友列表就是实现的类型效果.使用Expandable ...

  5. 【OpenCV】直方图

    今天写直方图,学了几个相关函数 1. mixChannels void mixChannels(const Mat* src, int nsrc, Mat* dst, int ndst, const ...

  6. NEFU 504 new Flip Game (高斯消元)

    题目链接 题解:和 poj1753Filp game 差不多,区别在于t组数据并且翻转的时候多了一个左上角. #include <iostream> #include <cstdio ...

  7. HTML/CSS题库

    一.    填空题 使用文本编辑器编辑完HTML后,扩展名可以是__html___或___htm__. 表格的标签是____table______,单元格的标签是____td______. 在编辑ta ...

  8. php Internal Server Error

    Internal Server Error The server encountered an internal error or misconfiguration and was unable to ...

  9. ios Push证书 转换步骤

    1.将aps_developer_identity.cer转换成aps_developer_identity.pem格式openssl x509 -in aps_developer_identity. ...

  10. iOS-Runtime-Headers

    iOS8.4 及之前的头文件 私有及共有API https://github.com/nst/iOS-Runtime-Headers