orderID、userID、orderStatus (1、2、3)、および orderTime を持つ「userorders」のテーブルがあります。
orderStatus 1 を持つ userid = 1 について、過去 6 か月間の最後の 150 件の注文の割合を計算したいと考えています。
両方の注文ステータス (1、2/3) に対して 2 つのクエリを作成してから、注文の割合を計算しようとしましたが、クエリが正しくありません。
私のコードとクエリ:
$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;
問題を解決したり、コードを改善するにはどうすればよいですか。