简体   繁体   English

如何在Codeigniter的查询生成器中使用select

[英]How to use select in Codeigniter's Query Builder

Given the following code: 给出以下代码:

$this->db->select();

the parameters in the select function are the names of the columns selected from the data base. select函数中的参数是从数据库中选择的列的名称。

Suppose that one of the parameters inserted is: COUNT(column_name) . 假设插入的参数之一是: COUNT(column_name)

Does it mean that only one row will be selected? 这是否意味着只会选择一行? (because COUNT returns a single value)

You can use like this: 您可以这样使用:

$this->db->select('COUNT(column_name) AS Total, other_column_name');
$this->db->from('Table_name');

Does it mean that only one row will be selected ? 这是否意味着只会选择一行? (because COUNT returns a single value) (因为COUNT返回单个值)

Of course yes, only one row will be selected, since the count is an aggregate operator, which makes only one row returned. 当然可以,将只选择一行,因为该计数是一个聚合运算符,因此只返回一行。

Please note using an aggregate function without a GROUP BY will always return one row, no matter what. 请注意,使用不带GROUP BY的聚合函数无论如何都将始终返回一行。 You must use a GROUP BY if you want to return more than one row. 如果要返回多个行,则必须使用GROUP BY

For more details read this 有关更多详细信息,请阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM