Mysql 如何在下面的查询中定义where条件(例如:userid!=0)?
如何在下面的查询中定义where条件?除了需要显示的零值外,从数据库中生成Mysql 如何在下面的查询中定义where条件(例如:userid!=0)?,mysql,joomla,Mysql,Joomla,如何在下面的查询中定义where条件?除了需要显示的零值外,从数据库中生成 private function totalVisitedPagesPerUser() { $query = "SELECT COUNT(*), " . $this->_db->quoteName('customer_name') . "," . "\n MAX(". $this->_db->quoteName('visit_t
private function totalVisitedPagesPerUser() {
$query = "SELECT COUNT(*), " . $this->_db->quoteName('customer_name') . "," .
"\n MAX(". $this->_db->quoteName('visit_timestamp') . ")," . $this->_db->quoteName('browser') . "," .
$this->_db->quoteName('os') . "," .
$this->_db->quoteName('session_id_person') . "," .
$this->_db->quoteName('ip') . "," .
"\n SUM(" . $this->_db->quoteName('impulse') . ")," .
$this->_db->quoteName('geolocation') .
"\n FROM ( SELECT * FROM #__realtimeanalytics_serverstats " . $this->whereQuery . " ORDER BY `visit_timestamp` DESC) AS INTABLE" .
$this->whereQuery .
"\n GROUP BY " . $this->_db->quoteName('session_id_person') .
"\n ORDER BY " . $this->_db->quoteName('customer_name');
$this->_db->setQuery($query);
$results = $this->_db->loadRowList();
if ($this->_db->getErrorNum()) {
throw new JRealtimeException(JText::sprintf('COM_JREALTIME_ERROR_RECORDS', $this->_db->getErrorMsg()), 'error');
}
return $results;
}
您可以通过在查询开始前检查条件来准备where condition变量,而不是在该点追加该变量,如:
$wherecondtion = "Where 1=1";
if($condition1){$wherecondtion."AND (add required filter 1)"}
if($condition2){$wherecondtion."AND (add required filter 2)"}
您的子查询如下所示:
"( SELECT * FROM #__realtimeanalytics_serverstats " . $wherecondtion . " ORDER BY `visit_timestamp` DESC)"
这是您需要的东西还是其他东西?有人来解决这个问题吗?这是您的问题:是添加到子查询中还是添加到主查询中?你能澄清一下吗?在子查询中添加。。。在数据库id中,其中与零混合,所以我需要显示除零值之外的其他值