我想计算表字段的计数(n_id)。我想计算nid并允许基于count的排序。我有基于nid的排序代码我想根据nid计数进行排序,如图所示
$data['link_click_count']['table']['join'] = array(
'node' => array(
'handler' => 'views_join',
'left_table' => 'node',
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['link_click_count']['nid'] = array( //sorting based on nid
'title' => t('Link Node id'),
'help' => t('Link Node id.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
);
答案 0 :(得分:0)
SELECT * FROM
(
SELECT COUNT(NID) CNT FROM TABLENAME GROUP BY NID
)Z ORDER BY Z.CNT
请尝试以上代码。 希望这会有所帮助。
答案 1 :(得分:0)
尝试此查询
SELECT nid, count(1) FROM table GROUP BY nid ORDER BY count(1)