1.SELECT PRODUCT_NAME, PRODUCT_PRICE*0.8 FROM PRODUCT
此处可以直接用乘法,取出的是打折后的价格
---------------------------------------------------------------------------------------------------------------
2.select user_name,to_char(sysdate,'YYYY')-to_char(user_birthday,'YYYY') as user_age from user
此处可以用to_char函数计算出日期的年部分,然后相减得出用户的年龄
---------------------------------------------------------------------------------------------------------------
3.select user_birthday from user where between '1-1-83' and '1-1-84'
检索生日大于83年1月1日,且小于84年1月1日的;与之相反,not between ... and ...则是大于等于下限值,小于等于上限值
---------------------------------------------------------------------------------------------------------------
4.通配符
_:一个下划线表示任意单个字符
%:表示任意多个字符(含0个字符)
[abc]或[a-c]:属于字符集合中的任意一个字符
[^abc]或[^a-c]:不属于字符几何中的任意一个字符
---------------------------------------------------------------------------------------------------------------
5.空值判断
is null不能用 = null 来代替;null也不等于''
---------------------------------------------------------------------------------------------------------------
6.rownum
select * from user where rownum <= 10
查询前10条;rownum是从1开始的!
---------------------------------------------------------------------------------------------------------------
7.group by
select categroy_id , count(product_id) from product group by category_id
一般group by 都会跟着统计函数在一起 如:count(...)
---------------------------------------------------------------------------------------------------------------
8.having
select categroy_id , count(product_id) from product group by category_id having count(product_id)>10
对分组的数据进行过滤,不能使用where子句,因为where子句在分组之前执行过滤,having子句在分组之后执行过滤
---------------------------------------------------------------------------------------------------------------
9.exists
select product_id from product where exists ( select * from important_product )
exists返回的是一个逻辑值;与之相反是not exists
---------------------------------------------------------------------------------------------------------------
10.All与any
select price from product where price < all ( select price from important_product)
< all小于子查询结果集中的最小值
> all大于子查询结果集中的最大值
> any 大于子查询结果集中的最小值
< any 小于子查询结果集中的最大值
---------------------------------------------------------------------------------------------------------------
其他容易记住的就不一一列出了