0
我有一個'用戶訂單'的表,其中有orderID,userID,orderStatus(可以是1,2,3)和orderTime。查詢一段時間的訂單百分比和訂單數
我要計算過去150級的訂單的百分比,在過去6一個月具有orderStatus 1.
我試圖寫的兩個查詢兩個訂單狀態(1,2/3)用戶ID = 1,然後計算訂單的百分比,但我的查詢不正確。
我的代碼和查詢:
$rs1 = mysql_query("select count(*) as orderCount1 from userorders where
orderStatus = 1 and orderID in (select top 150 orderID from userorders where
userid = 1 and orderStatus in (1,2,3) and
orderTime > ".strtotime("-6 month")." oder by orderID desc)") or
die (mysql_error());
$rs2 = mysql_query("select count(*) as orderCount1 from userorders where
orderStatus in (2,3) and orderID in (select top 150 orderID from userorders where
userid = 1 and orderStatus in (1,2,3) and
orderTime > ".strtotime("-6 month")." order by orderID desc)") or
die (mysql_error());
$orderCount1 = $rs1['orderCount1'];
$orderCount2 = $rs2['orderCount2'];
$orderPercent = ($orderCount1/ $orderCount1+$orderCount2)*100;
我怎樣才能解決這個問題或改善我的代碼。
你想找到的百分比所有訂單中的orderStatus = 1? – vinculis
http://stackoverflow.com/questions/1576370/getting-a-percentage-from-mysql-with-a-group-by-condition-and-precision – ethrbunny
@ethrbunny我檢查這個Q和A,爲答案它返回50個代理人的數字,但我想獲得一個平均值爲ordestatus的數字。 – Ali