获取 0 到 100 之间的记录而不使用 between in mysql
Fetch records between 0 and 100 without using between in mysql
我想在 mysql 中获取 0 到 100 之间的记录而不使用 between
子句,因为当我使用这样的查询时
$this->db->having('distance between 0 and 100');
我收到如下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near between0 and 100
您会看到 0
前面没有 space,因此该语句会产生错误。
如何确保 space 保留在 0 之前,否则:如何在查询中排除 between
怎么样
$this->db
->group_start()
->where('distance <=', 100)
->where('distance >=', 0)
->group_end();
如果你删除组语句以防万一你不需要它就完全没问题了
使用
$this->db->having(array('distance >=' => 0, 'distance <=' => 100));
// Produces: HAVING distance => 0, distance <= 100
获得这个的两种简单方法
$this->db->select("*");
$this->db->from("table-name");
$this->db->where('distance >=', 0)
$this->db->where('distance <=', 100);
$query = $this->db->get();
return $query->result();
或
$query = $this->db->query("SELECT * FROM table-name WHERE distance <= 100 AND distance >= 0");
return $query->result(); //or $query->result_array();
我想在 mysql 中获取 0 到 100 之间的记录而不使用 between
子句,因为当我使用这样的查询时
$this->db->having('distance between 0 and 100');
我收到如下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
between0 and 100
您会看到 0
前面没有 space,因此该语句会产生错误。
如何确保 space 保留在 0 之前,否则:如何在查询中排除 between
怎么样
$this->db
->group_start()
->where('distance <=', 100)
->where('distance >=', 0)
->group_end();
如果你删除组语句以防万一你不需要它就完全没问题了
使用
$this->db->having(array('distance >=' => 0, 'distance <=' => 100));
// Produces: HAVING distance => 0, distance <= 100
获得这个的两种简单方法
$this->db->select("*");
$this->db->from("table-name");
$this->db->where('distance >=', 0)
$this->db->where('distance <=', 100);
$query = $this->db->get();
return $query->result();
或
$query = $this->db->query("SELECT * FROM table-name WHERE distance <= 100 AND distance >= 0");
return $query->result(); //or $query->result_array();