牛骨文教育服务平台(让学习变的简单)
博文笔记

在tp中数据去重并获取自定义字段

创建时间:2017-06-12 投稿人: 浏览次数:1256

在tp中提供了去重的功能tp文档distinct

用文档中提供的distinct方法去重只能获取数据中能获取field中的字段数据,代码如下

//会员模型
$member_model = M("");
$current_time = date("Y-m", time());
$map = array(
   "member_id" => array("exp", "is not null"),
   "date_format(`send_time`, "%Y-%m")" => $current_time
);
$no_relation_list = $member_model->where($map)->distinct(true)->field("name, phone as mobile")->select();

后来用的是group方法去重获取自定义字段,代码如下

//会员模型
$member_model = M("");
$current_time = date("Y-m", time());
$map = array(
   "member_id" => array("exp", "is not null"),
   "date_format(`send_time`, "%Y-%m")" => $current_time
);
$no_relation_list = $member_model
->where($map)
->group("member_id")
->distinct(true)
->field("member_id, name name, phone mibile")
->select();
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。