`
lonelystarxing
  • 浏览: 46930 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

sql查询昨天记录,遍历最高N条记录

阅读更多

1,sql查询发生在昨天的记录

SELECT * FROM `articles`
WHERE created_at>=(current_date - interval 1 day) and 
created_at<=(current_date - interval 0 day)

 

2,关联表遍历分数最高的三条相关记录

表a,s

其中关联字段为a.id=s.article_id

取前三条记录sql语句为

SELECT * FROM `articles` a
JOIN (SELECT * FROM `scores` ORDER BY score DESC LIMIT 3)s
WHERE a.id = s.article_id

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics