自己在网上找了些SQL资料
1:解决重复问题
select distinct 列名 from 表名
2:获取时间
to_char(sysdate, 'yyyy-MM-dd HH24:mi:ss')
select to_char(sysdate,'yyyy') from dual; --年
select to_char(sysdate,'Q' from dual; --季
select to_char(sysdate,'mm') from dual; --月
select to_char(sysdate,'dd') from dual; --日
3:as
select column_1 as 列1,column_2 as 列2 from table as 表2
上面的语句就可以解释为,选择 column_1 作为 列1,column_2 作为 列2 从 table 当成 表2
4:rank() over()
详细见:
http://blog.youkuaiyun.com/luofuit/article/details/40154423
5:decode()函数
decode()函数简介:
主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明);
使用方法:
Select decode(columnname,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)
From talbename
Where …
其中columnname为要选择的table中所定义的column,
·含义解释:
decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)的理解如下:
if (条件==值1)
then
return(翻译值1)
elsif (条件==值2)
then
return(翻译值2)
......
elsif (条件==值n)
then
return(翻译值n)
else
return(缺省值)
end if
6:union 和 union all
union 检查重复 union all 不做检查 比如 select 'a' union select 'a' 输出就是一行 a 比如 select 'a' union all select 'a' 输出就是两行 a7:group by
详情见 http://blog.youkuaiyun.com/luofuit/article/details/40155611
8:select查询后,为查询结果集其别名
select a as aa,b as bb, c as cc from t as tt;或者:
SELECT
A
FROM
(
SELECT
A,B
FROM
TABLE
) T
where
A=
'XXXX'
;
T:为查询后的结构集别名
后面则可以
select T.* from(select a,b,c from bi)T;