你能幫助我PHP MySQL的排序行降數
$sql="select * from table1 where id='1,2,3,4'";
{
$sql2="select distinct column1 from table2 where column2='".$row['id']."' and left(date,10) BETWEEN '".$date_from."' AND '".$date_to."'";
}
我需要ID
你能幫助我PHP MySQL的排序行降數
$sql="select * from table1 where id='1,2,3,4'";
{
$sql2="select distinct column1 from table2 where column2='".$row['id']."' and left(date,10) BETWEEN '".$date_from."' AND '".$date_to."'";
}
我需要ID
如果我按行降序爲$ SQL2的數量進行排序$ SQL理解正確的話,你想從$sql
結果在$sql
通過$sql2
每一行中的行數排序。這個連接應該做到這一點,它加入table2,並通過計數降序下達。
SELECT t1.id
FROM table1 t1
LEFT JOIN table2 t2
ON t1.id=t2.column2
WHERE id IN (1,2,3,4) -- should it really be = '1,2,3,4'?
AND LEFT(date,10) BETWEEN '2013-01-01' AND '2013-12-31'
GROUP BY t1.id
ORDER BY COUNT(DISTINCT t2.column1) DESC
爲什麼你會在包裝'{}'第二個查詢? – 2013-05-12 11:44:06