Page 1 of 1

ตัวอย่างใช้ SQL GROUP BY กับ SQL SUM

Posted: 20/01/2016 11:14 am
by thatsawan
Image

Code: Select all

$sql_array = array(
            'SELECT' => 'tag_name,tag_id,SUM(num_row)',
            'FROM' => array(
                $this->table_prefix . tables::TAGS_HOT => 't'
            ),
            'GROUP_BY' => 'tag_id DESC',
            

        );
        
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        echo $sql; exit;

Code: Select all

SELECT tag_name,tag_id,SUM(num_row) FROM (phpbb_m_tag_hot t) GROUP BY tag_id DESC
Image


เพิ่มเติมได้ที่
http://www.w3resource.com/sql/aggregate ... oup-by.php