/** * build the query for the avg caclculation * @param model $tableModel * @param string $label the label to apply to each avg * @return string sql statement */ protected function getMedianQuery(&$tableModel, $label = "'calc'") { $fields = $tableModel->getDBFields($this->getTableName(), 'Field'); if ($fields[$this->getElement()->name]->Type == 'time') { $name = $this->getFullName(false, false, false); $table =& $tableModel->getTable(); $joinSQL = $tableModel->_buildQueryJoin(); $whereSQL = $tableModel->_buildQueryWhere(); return "SELECT SEC_TO_TIME(TIME_TO_SEC({$name})) AS value, {$label} AS label FROM `{$table->db_table_name}` {$joinSQL} {$whereSQL}"; } else { return parent::getMedianQuery($tableModel, $label); } }