Chinaunix首页 | 论坛 | 博客
  • 博客访问: 51363
  • 博文数量: 15
  • 博客积分: 1470
  • 博客等级: 上尉
  • 技术积分: 177
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-12 15:44
文章分类
文章存档

2011年(15)

我的朋友

分类: 数据库开发技术

2011-01-30 18:12:26

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

阅读(371) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~