我想使用codeigniter query_builder函数。没有想法,请帮助。
$this->db->query("SELECT city as popularcity FROM(SELECT city,count(city) as
countcity FROM ads LIMIT 0, 6) as t ORDER BY MAX(countcity)");
答案 0 :(得分:0)
$this->db->query("SELECT city as popularcity, countcity
FROM
(SELECT city, count(city) as countcity FROM ads GROUP BY city) as t
ORDER BY countcity DESC LIMIT 0, 6");
答案 1 :(得分:0)
尝试以下代码,
$this->db->select("city as popularcity, countcity");
$this->db->from("(SELECT city, count(city) as countcity FROM ads GROUP BY city) as t");
$this->db->order_by("countcity DESC");
$this->db->limit(0,6);