gpt4 book ai didi

mysql - 如何在下面的查询中定义 where 条件(例如 : userid ! = 0)?

转载 作者:行者123 更新时间:2023-11-29 19:32:22 25 4
gpt4 key购买 nike

如何定义下面的查询中的where条件?形成数据库,除了需要显示的零值

 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;
}

最佳答案

您可以通过在查询开始之前检查条件来准备条件变量,然后在该点附加该变量,例如:

$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)"

这是您需要的东西还是不同的东西?

关于mysql - 如何在下面的查询中定义 where 条件(例如 : userid ! = 0)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41719153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com