I've got a table of 'userorders' which have orderID, userID , orderStatus (which can be 1,2,3) and orderTime.
I want to calculate percent of last 150 orders, in last 6 month for userid = 1 which has orderStatus 1.
I tried to write two queries for both orders Status (1, 2/3) and then calculate percent of orders but my queries are not correct.
my code and queries:
$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;
How can I solve the problem or improve my codes.