构建kohana复杂的sql语句

kohana 同时被 3 个专栏收录
0 篇文章 0 订阅
10 篇文章 0 订阅
3 篇文章 0 订阅

Selecting only specific columns


DB::select('column1','column2')->from('table_name');

SELECT `column1`, `column2` FROM `table_name`

Selecting Column AS


DB::select(array('column','my_column'))->from('table_name')->compile($db);

SELECT `column` AS `my_column` FROM `table_name`

join()


DB::select()->from('table_name')->join('table_2')->on('table_2.table_id', '=', 'table_name.id');

SELECT * FROM `table_name` JOIN `table_2` ON `table_2`.`table_id` = `table_name`.`id`

group_by()


DB::select()->from('table_name')->group_by('column');

SELECT * FROM `table_name` GROUP BY `column`

DB::select()->from('table_name')->group_by(array('column1', 'mycol'));

SELECT * FROM `table_name` GROUP BY `column1` AS `mycol`

having()


DB::select()->from('table_name')->having('column','=','value');

SELECT * FROM `table_name` HAVING `column` = 'value'

and_having()


DB::select()->from('table_name')->having('column','=','value')->and_having('column2','=','value');

SELECT * FROM `table_name` HAVING `column` = 'value' AND `column2` = 'value'

or_having()


DB::select()->from('table_name')->having('column','=','value')->or_having('column2','=','value');

SELECT * FROM `table_name` HAVING `column` = 'value' OR `column2` = 'value'

having_open()


DB::select()->from('table_name')->having_open()->having('column','=','value')
->or_having('column2','=','value')->having_close();

SELECT * FROM `table_name` HAVING (`column` = 'value' OR `column2` = 'value')

and_having_open()


DB::select()->from('table_name')->where('column','=','value')->and_having_open()->having('column2','=','value')
->and_having('column3','=','value')->and_having_close();

SELECT * FROM `table_name` WHERE `column` = 'value' HAVING (`column2` = 'value' AND `column3` = 'value')

or_having_open()


DB::select()->from('table_name')->where('column','=','value')->or_having_open()->having('column2','=','value')
->or_having('column3','=','value')->or_having_close();

SELECT * FROM `table_name` WHERE `column` = 'value' HAVING (`column2` = 'value' OR `column3` = 'value')

order_by()


DB::select()->from('table_name')->order_by('column', 'ASC');

SELECT * FROM `table_name` ORDER BY `column` ASC

limit()


DB::select()->from('table_name')->limit(10);

SELECT * FROM `table_name` LIMIT 10

offset()


DB::select()->from('table_name')->limit(10)->offset(50);

SELECT * FROM `table_name` LIMIT 10 OFFSET 50

where()


DB::select()->from('table_name')->where('column','=','value');

SELECT * FROM `table_name` WHERE `column` = 'value'

and_where()


DB::select()->from('table_name')->where('column','=','value')->and_where('column2','=','value');

SELECT * FROM `table_name` WHERE `column` = 'value' AND `column2` = 'value'

or_where()


DB::select()->from('table_name')->where('column','=','value')->or_where('column2','=','value');

SELECT * FROM `table_name` WHERE `column` = 'value' OR `column2` = 'value'

where_open()


DB::select()->from('table_name')->where_open()->where('column','=','value')
->or_where('column2','=','value')->where_close();

SELECT * FROM `table_name` WHERE (`column` = 'value' OR `column2` = 'value')

and_where_open()


DB::select()->from('table_name')->where('column','=','value')->and_where_open()->where('column2','=','value')
->or_where('column3','=','value')->and_where_close();

SELECT * FROM `table_name` WHERE `column` = 'value' AND (`column2` = 'value' OR `column3` = 'value')

or_where_open()


DB::select()->from('table_name')->where('column','=','value')->or_where_open()->where('column2','=','value')
->and_where('column3','=','value')->or_where_close();
  SELECT * FROM `table_name` WHERE `column` = 'value' OR (`column2` = 'value' AND `column3` = 'value')
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值