Oracle-Sql语句使用笔记

一些常用的SQL语句
一.判断在某段时间内
1)to_date
select * from table where talbe.time between to_date('2006-1-15','yyyy-mm-dd') and to_date('2008-1-15','yyyy-mm-dd') order by talbe.time;

2)trunc
select * from table where talbe.time between trunc(date(formDate) )and trunc(date(toDate) )order by talbe.time;

二.查询匹配%
select * from table where lower(table.username) like % + username.toLower()%;

三.如何获得前N条记录
SELECT * FROM TABLE WHERE ROWNUM<=N

四.查看表字段的详细信息
desc table;

五.SUM和Group
select sum(ig.gather_sum) from intend_gather ig group by ig.project_number;

六.left join
select * from intend_gather ig left join actual_gather ag on ig.intend_id=ag.intend_id order by ig.intend_id desc

你可能感兴趣的:(oracle,sql)