1. field 过滤掉某些字段
field('delete_time')->select(); //过滤delete_time字段
2. field 写入字段合法性检测
field('name')->create(); //仅新增name字段
3. field 操作新增字段
field('0 as selected'); //将0赋值给新增字段selected
4. field 运算 +-*/
->field('coupn+paper as card'); //优惠券数量(Number)+红包数量(Number)=card(卡包)
5. field 使用函数
->field('intval(price) as price'); //对价格字段Price取整格式化
->field('count(user_id) as user_count')->order('user_count'); //安装用户数据条数进行排序
->field(sum(price) as user_price)->order(user_price); //安装用户金额汇总进行排序
6. field sum 统计次数
field('sum(status = 1) as user_sum'); //status=1数据求和
7. field case when 的使用
->field('count(id) as all_count,IFNULL(SUM(CASE WHEN has_img = 2 THEN 1 END),0) as has_img_count,IFNULL(SUM(CASE WHEN star_rank = 1 THEN 1 END),0) as goods_review_count,IFNULL(SUM(CASE WHEN star_rank = 2 THEN 1 END),0) as middle_review_count,IFNULL(SUM(CASE WHEN star_rank = 3 THEN 1 END),0) as bad_review_count')->where($where)->find();
8. field 里作判断
->field("if(price > $money,1,-1) as status"); //status = price > $money ? 1 : -1
9. field group 之后 某一个字段以“,”分割形式展示
->group(id)->field('group_concat(score order by `score ` desc) as score');
10. group 之后 field 里面查询最新一条里面的数据
->group('status')->field('SUBSTRING_INDEX(group_concat(id order by `id` desc),",",1) as id');