在我的sql表中,我有超过300000个条目。
$marketname = more then 200 !
使用此选项我可以看到最后15个条目。
$sql = "SELECT price FROM markets where market = '" . $marketname . "' order by time desc LIMIT 15,1";
$sql = "SELECT price FROM markets where market = '" . $marketname . "' order by time desc LIMIT 15,1";
等等,最后30,60,120。
$sql = "SELECT price FROM markets where market = '" . $marketname . "' order by time desc LIMIT 30,1";
$sql = "SELECT price FROM markets where market = '" . $marketname . "' order by time desc LIMIT 60,1";
但是有没有一个组合,因为当我在一个页面上展示它在200个市场时非常慢!!
喜欢..
$sql = "SELECT price FROM markets where market = '" . $marketname . "' order by time desc LIMIT 15,1 AND LIMIT 30,1 AND LIMIT 60,1 AND LIMIT 120,1";
答案 0 :(得分:0)
首先,尽量不要做SQL注入式SQL。将PDO或MySQLi与预准备语句一起使用。考虑到这一点,请不要限制查询的最后部分。
SELECT price FROM markets WHERE market = :marketName ORDER BY time DESC limit 100
将通过marketname(准备声明)查询市场价格,订购并将其限制为100条记录。