我在mysql中有一个表,它有三列,一是用户购买它的代码,另一个是这个代码购买的时间,最后一个是买家电话号码;例如:
#CODE #phone #date
2154856265 3214490 2013-08-15
所以现在我怎样才能以 php 格式进行查询,返回这个语句:我想要用户 = 3214490 按日期排序的最后 10 个代码?
谢谢你的病人;)
你开玩笑的对吧?这是一个微不足道的查询。
select code
from table
where phone = 3214490
order by date desc
limit 10
你可以尝试这样的事情: -
SELECT * FROM (
SELECT * FROM table where user = 3214490 ORDER BY date DESC LIMIT 10
) sub
ORDER BY date ASC
假设您使用“电话”作为用户 ID,您需要这样的查询:
SELECT * FROM [table_name] WHERE `phone` = 3214490 ORDER BY `date` DESC LIMIT 10
将 [table_name] 替换为存储这些记录的表的名称,因为您没有在问题中指定它。
select c.code from directory c where c.phone= '3214490' order by c.date limit 0,10
这可能会有所帮助