sql语句书写小技巧

版权声明: https://blog.csdn.net/qq_36311845/article/details/81092990

一、sql语句书写顺序

           select--->from--->where--->group by--->having--->order by

二、sql语句解析顺序

         from--->where--->group by---> having--->select--->order by

三 sql 语句的一些常用关键字

count:计数函数

实例:select count(*) from ckx_shengcx
(实例说明:计算出有多少条数据)

distinct  去重函数

使用案例 :select  count(distinct(chanx)) from ckx_shengcx t where t.chanx = 'L3'
(语句说明:可能在不同工厂里有好几个产线,可能有好几个L3产线,通过去重,我们就可以得到只有一个L3产线啦)

四 Oracle 常用的函数

1.字符串转换成时间函数 to_char()

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual;   //日期转化为字符串   
select to_char(sysdate,'yyyy') as nowYear   from dual;   //获取时间的年   
select to_char(sysdate,'mm')    as nowMonth from dual;   //获取时间的月   
select to_char(sysdate,'dd')    as nowDay    from dual;   //获取时间的日   
select to_char(sysdate,'hh24') as nowHour   from dual;   //获取时间的时   
select to_char(sysdate,'mi')    as nowMinute from dual;   //获取时间的分   
select to_char(sysdate,'ss')    as nowSecond from dual;   //获取时间的秒

2.字符串转时间函数 to_date

这是笔者在实际开发中的代码

to_date()函数的使用,及其时间直接比较大小(t1.KAISRQ在表中就是date数据类型)

3.忽略大小字母进行查询

upper 是将小写装换成大写

lower 是将大写装换成小写,并用or进行连接

猜你喜欢

转载自blog.csdn.net/qq_36311845/article/details/81092990