# 函数原型
~~~
public function having($mixCond /* args */);
~~~
having 和 where 用法一致,只是没有 where exists 这种写法。
# 字段 (表达式) 值
~~~
# SELECT `test`.`tid` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`tid` HAVING `test`.`tid` > 5
database::table ( 'test', 'tid as id,tname as value' )
->groupBy('tid')
->having('tid','>',5)
->getAll ();
~~~
# 以数组直接传入
~~~
# SELECT `test`.`name` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`name` HAVING `test`.`name` LIKE '技术'
database::table ( 'test', 'name as id,tname as value' )
->groupBy('name')
->having(['name','like', '技术'] )
->getAll ();
~~~
# OrHaving 语法
~~~
# SELECT `test`.`name` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`name` HAVING `test`.`name` LIKE '技术' OR `test`.`tname` LIKE '技术'
database::table ( 'test', 'name as id,tname as value' )
->groupBy('name')
->having(['name','like', '技术'] )
->orHaving(['tname','like', '技术'])
->getAll ();
~~~
# havingBetween 语法
~~~
# SELECT `test`.`name` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`name` HAVING `test`.`id` BETWEEN 1 AND 10 AND `test`.`id` BETWEEN 1 AND 100
database::table ( 'test', 'name as id,tname as value' )
->groupBy('name')
->having('id','between', [1,10])
->havingBetween('id', [1, 100])
->getAll ();
~~~
# havingBetween 二维数组语法支持
后面的语法均支持这样的写法,后面不再继续示例了。
~~~
# SELECT `test`.`name` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`name` HAVING `test`.`name` BETWEEN 1 AND 100 AND `test`.`tname` BETWEEN 5 AND 22
database::table ( 'test', 'name as id,tname as value' )
->groupBy('name')
->havingBetween( [ ['name', [1, 100]], ['tname', [5, 22]] ])
->getAll ();
~~~
# havingNotBetween 语法
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`name` HAVING `test`.`id` NOT BETWEEN 1 AND 10 AND `test`.`id` NOT BETWEEN 1 AND 100
database::table ( 'test')
->groupBy('name')
->having('id','not between', [1,10])
->havingNotBetween('id', [1, 100])
->getAll ();
~~~
# havingIn 语法
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`name` HAVING `test`.`id` IN (2,50) AND `test`.`num` IN (2,50)
database::table ( 'test')
->groupBy('name')
->having('id','in', [2,50])
->havingIn('num', [2,50])
->getAll ();
~~~
# havingNotIn 语法
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`name` HAVING `test`.`id` NOT IN (2,50) AND `test`.`num` NOT IN (2,50)
database::table ( 'test')
->groupBy('name')
->having('id','not in', [2,50])
->havingNotIn('num', [2,50])
->getAll ();
~~~
# havingNull 语法
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`name` HAVING `test`.`id` IS NULL AND `test`.`num` IS NULL
database::table ( 'test')
->groupBy('name')
->having('id','null')
->havingNull('num')
->getAll ();
~~~
# havingNotNull 语法
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`name` HAVING `test`.`id` IS NOT NULL AND `test`.`num` IS NOT NULL
database::table ( 'test')
->groupBy('name')
->having('id','not null')
->havingNotNull('num')
->getAll ();
~~~
# 分组查询
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`id` HAVING `test`.`id` = 5 OR (`test`.`votes` > 100 AND `test`.`title` <> 'Admin')
database::table ( 'test' )
->groupBy('id')
->having ( 'id', 5 )
->orHaving ( function ($objSelect) {
$objSelect->having ( 'votes', '>', 100 )->having ( 'title', '<>', 'Admin' );
} )
->getAll ();
# SELECT `test`.* FROM `test` GROUP BY `test`.`id` HAVING `test`.`id` = 5 OR `test`.`name` = '小牛' AND (`test`.`votes` > 100 OR `test`.`title` <> 'Admin')
database::table ( 'test' )
->groupBy('id')
->having ( 'id', 5 )
->orHaving ( 'name', '小牛' )
->having ( function ($objSelect) {
$objSelect->having ( 'votes', '>', 100 )->orHaving ( 'title', '<>', 'Admin' );
} )
->getAll ();
~~~
# 条件表达式支持
条件表达式由“{}”包起来表示支持条件表达式,“[]”表示支持字段格式化。
~~~
# SELECT `test`.`post`,`test`.`value`,concat("tt_",`test`.`id`) FROM `test` GROUP BY `test`.`id` HAVING concat("hello_",`test`.`posts`) = `test`.`id`
database::table ( 'test', 'post,value,{concat("tt_",[id])}' )
->groupBy('id')
->having ( '{concat("hello_",[posts])}', '=', '{[id]}' )
->getAll ();
~~~
# 字段作为键值
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`id` HAVING `test`.`id` = '故事' AND `test`.`name` IN (1,2,3) AND `test`.`weidao` BETWEEN '40' AND '100' AND `test`.`value` IS NULL AND `test`.`remark` IS NOT NULL AND `test`.`goods` = '东亚商品' AND `test`.`hello` = 'world'
database::table ( 'test' )
->groupBy('id')
->having ( [
'id' => [ '=','故事' ],
'name' => ['in',[1,2,3]],
'weidao' => ['between','40,100'],
'value' => 'null',
'remark' => ['not null'],
'goods' => '东亚商品',
'hello' => ['world']
] )->getAll ();
~~~
# string__ 支持(支持字段)
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`id` HAVING `test`.`name` = 11 and `post`.`value` = 22 and concat("tt_",`test`.`id`)
database::table ( 'test')
->groupBy('id')
->having (
['string__' => '{[name] = 11 and [post.value] = 22 and concat("tt_",[id])}']
)
->getAll ();
~~~
# subor__ 和 suband__ 支持
~~~
# SELECT `test`.* FROM `test` GROUP BY `test`.`id` HAVING `test`.`hello` = 'world' OR (`test`.`id` LIKE '你好')
database::table ( 'test')
->groupBy('id')
->having (
[
'hello' => 'world',
'subor__' => ['id','like','你好']
]
)
->getAll ();
# SELECT `test`.* FROM `test` GROUP BY `test`.`id` HAVING `test`.`hello` = '111' OR (`test`.`id` LIKE '你好' AND `test`.`value` = 'helloworld') AND (`test`.`id` LIKE '你好' OR `test`.`value` = 'helloworld' OR (`test`.`child_one` > '123' AND `test`.`child_two` LIKE '123'))
database::table ( 'test')
->groupBy('id')
->having (
[
'hello' => '111',
'subor__' => [
['id','like','你好'],
['value','=','helloworld']
],
'suband__' => [
'logic__' => 'or',
['id','like','你好'],
['value','=','helloworld'],
'subor__' => [
['child_one','>','123'],
['child_two','like','123'],
]
]
]
)
->getAll ();
~~~
- 关于 QueryPHP
- 获取 QueryPHP
- 环境要求
- 许可协议 Free
- 执行流程 MVC
- 命名规范 $sName
- 目录结构 DIR
- 单一入口 index.php
- 响应客户端请求 URL
- 命名空间与自动载入 Autoload
- 路由
- 路由导入
- 批量导入
- 参数正则
- 分组定义
- 路由绑定
- 路由域名
- 分层控制器
- 默认和初始化APP
- 默认控制器和方法
- url 模式
- url 生成
- url 伪静态
- url 重写
- url 重定向
- 控制器绑定
- 方法器分层
- 控制器 __init
- 控制器方法交互
- 模板引擎语法
- C变量输出 $sName
- C变量支持函数和方法 $sName|trim
- C快捷输出 ~
- C标签简化 Css & Javascript
- C默认值 eq 三元运算符
- C变量运算符 +-
- 变量递增递减 ++--
- C循环数据 list
- N变量赋值 assign
- N循环数据 list
- N循环数据高级版 lists
- C循环数据 while
- N循环数据 while
- C循环数据 for
- N循环数据 for
- C条件判断 if
- N条件判断 if
- 标签嵌套无限层级
- N循环流程 break & continue
- N使用 PHP 代码
- N包含子模板 include
- J模板引擎 intro
- J条件判断 if
- J循环数据 each
- J变量 & 表达式
- J变量支持函数和方法 hello|test
- J默认值 eq 三元运算符
- J框架前端组件 jquery.queryphp.js
- J前端 CSS 规范
- J前端 JS 规范
- 保护标签自身 tagself
- 数据库
- 数据库配置
- 执行原生 sql 语句
- 数据库事务
- 数据库构造器 prefix
- 数据库构造器 table
- 数据库构造器 forceIndex
- 数据库构造器 where
- 数据库构造器 bind
- 数据库构造器 join
- 数据库构造器 union
- 数据库构造器 orderBy
- 数据库构造器 groupBy
- 数据库构造器 having
- 数据库构造器 distinct
- 数据库构造器 aggregate
- 数据库构造器 limit
- 数据库构造器 forUpdate
- 数据库构造器 columns
- 数据库构造器 reset
- 数据库集合查询
- 数据库查询数据 get
- 数据库查询多条数据 getAll
- 数据库查询单条数据 getOne
- 数据库查询聚合查询 aggregate
- 数据库写入数据 insert
- 数据库写入数据 insertAll
- 配置
- 配置格式
- 惯性配置
- 配置文件
- 读取配置
- 设置配置
- 删除配置
- 日志
- 日志配置参数
- 日志路径
- 日志过滤器
- 日志处理器
- 缓存
- 缓存配置参数
- 缓存路径
- 缓存指定时间
- COOKIE
- COOKIE 配置参数
- 开发调试
- 页面 trace