gpt4 book ai didi

带有 SUM 和 WHERE 的 Mysql 查询不起作用

转载 作者:行者123 更新时间:2023-11-30 22:54:17 26 4
gpt4 key购买 nike

include 'conn.php';

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'saleid';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'desc';

$orderno = isset($_POST['orderno']) ? mysql_real_escape_string($_POST['orderno']) : '';

$offset = ($page-1)*$rows;
$result = array();

$where = "orderno like '$orderno%'";
$rs = mysql_query("select count(*) from tblsales where " . $where);
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("select *, sum(price+shipping+paypalfee+storefee) as totalcost from tblsales group by orderno where " . $where . " order by $sort $order limit $offset,$rows");

$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;

echo json_encode($result);

您能否更改此查询,使其在使用 WHERE 子句时返回表中的所有记录,以便我可以在需要时搜索特定记录。目前它不返回任何东西:

  select *, sum(price+shipping+paypalfee+storefee) as totalcost
from tblsales
group by orderno
where " . $where . "
order by $sort $order
limit $offset,$rows

最佳答案

试试这个

select *,sum(totalcost) 
FROM (select *, price+shipping+paypalfee+storefee as totalcost from tblsales) x
group by orderno
where " . $where . "
order by $sort $order
limit $offset,$rows

关于带有 SUM 和 WHERE 的 Mysql 查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27077850/

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