常用sql

工作中经常碰到一些需要查询数据库,有的时候不同数据库会有不同的查询方法,记录一下..

查询某列中以数字开头的结果

1.mysql:

SELECT *
FROM MyTable
WHERE MyColumn REGEXP '^[0-9]';

2.postgres

SELECT * FROM books WHERE title ~ '^\d+ ?'
select * from books where convert(char(32), book_id) like '7%'

 

postgres里日期查询

select TIMESTAMP 'yesterday';
select DATE 'yesterday';
select TIMESTAMP 'today';
select DATE 'today';
select TIMESTAMP 'tomorrow';
select DATE 'tomorrow';
select TIME 'allballs';
select now();
select TIMESTAMP 'now';
select DATE 'now';
select current_date;

 

posted @ 2013-09-04 14:31  夏木友人  阅读(133)  评论(0编辑  收藏  举报