MySQL查詢一個表的前25%的數據,SQL如下:
SELECT g.* FROM (SELECT @rownum:=0) r join tb_shopping_car g where (@rownum:=@rownum+1)<=(select round(count(*)*0.25) from tb_shopping_car);
此題在sqlserver和oracle中都非常簡單,但是mysql不支持TOP函數,在MySQL中就非常難了。
MySQL查詢一個表的前25%的數據,SQL如下:
SELECT g.* FROM (SELECT @rownum:=0) r join tb_shopping_car g where (@rownum:=@rownum+1)<=(select round(count(*)*0.25) from tb_shopping_car);
此題在sqlserver和oracle中都非常簡單,但是mysql不支持TOP函數,在MySQL中就非常難了。