SQL语句
来源:互联网 发布:乐乎 编辑:程序博客网 时间:2024/06/16 08:56
mysql:
给指定日期加一天用date_add函数 INterval 1 day
select * from a,b where where a.company like '%张%' and a.id=b.company_id and otime>='2014-10-31' and otime<date_add('2014-11-3', INTERVAL 1 day) order by b.otime limit 0,1000
如何查询上一条数据和下一条数据,这种写法为了防止:当你点击当前这一条数据7829时,如果正在这时别人删除了这条数据7829,如何给用户显示上一条数据和下一条数据:
(select '00' tag, id,title,instructions,pic, picsmall from a where id=7829)UNION ALL(select '01' tag, id,title,instructions,pic, picsmall from a where id > 7829 limit 1) -- <!-- 下一条 --> UNION ALL(select '02' tag, id,title,instructions,pic, picsmall from a where id < 7829 order by id DESC limit 1) -- <!-- 上一条 -->
以上做法似乎是行不通的。可以试试以下方法:
select vtb.tag,a.id,a.title,a.instructions,a.pic,a.pic_small picsmall from (select '00' tag,7829 vid) vtb left join a on vtb.vid = tb_mito.id UNION ALL select vtb.tag,a.id,a.title,a.instructions,a.pic,a.pic_small picsmall from (select '01' tag,(select id from tb_mito where id >7829 limit 1) vid) vtb left join a on vtb.vid = a.id UNION ALL select vtb.tag,a.id,a.title,a.instructions,a.pic,a.pic_small picsmall from (select '02' tag,(select id from a where id < 7829 order by id DESC limit 1) vid) vtb left join a on vtb.vid = tb_mito.id
0 0
- SQL语句
- sql语句
- SQL语句
- SQL语句
- SQL语句
- SQL语句
- SQL语句
- SQL语句
- SQL 语句
- sql语句
- sql语句
- Sql语句
- SQL语句
- SQL语句
- sql语句
- SQL 语句
- sql语句
- sql语句
- 分享Android实现无线点餐系统
- Move.c && Move.h
- 指针函数 和 函数指针 指针为参数时使用堆内存
- SQL表关联中的逻辑与效率(二)
- VC ACTIVEX 控件网页打开错误8007007e
- SQL语句
- C++学习 boost学习之-Synchronization
- 第四部分:将状态数据添加到ToasterService实现(JMX Access)-数我的面包!
- java判断字符串中是否含有中文字符
- iOS动画——ViewAnimations
- 图表插件汇总
- 都是回车惹的祸- Redhat中cron之奇异行为索源
- Objective C运行时(runtime)技术的几个要点总结
- 左偏树 hdu1512