sql小知识

1:查询某一段落内的几条数据,按时间降序。

select * from FtpPublicFile order by date_created DESC limit #{page},10

2:创建视图,  查询出某些类别的数据,保存在视图中。  || 的优先级高于and

create view newpoint as select * from newslist where (pid=2 and id=1) || (pid=2 and id=2);

3:  查询出某些字段的数据。

select * from tablec where cat in {'c1','c2'};

4:查询出表中的前几条数据,top在mysql中 不支持,可以用limit代替。

select top 2 * from newpoint order by date_created desc;

 5:查询某些类别之后,union进行合并.    查询的两个表相加。

(select * from newpoint where pid=2 and id=1) union (select * from newpoint where pid=2 and id=2);

猜你喜欢

转载自www.cnblogs.com/liyafei/p/9400216.html