sql注意

1.先分页,再排序        

                 以下是先对表进行分页搜索,如搜索出来的结果是: 

                  a.在100条数据中的前10条数据集合A

                  b.再对集合A进行排序

 SELECT *
                        FROM (
                              SELECT 
                               MOVIE_UID AS PICTURE_RELATE_ID,
                              TITLE AS HOT_MOVIE_CACHE_NAME,
                              PICTURE_PATH,
                              START_TIME AS DATEINDATE_IN,
                              ROWNUM AS rownumber,
                              PICCACHEPATH
                              FROM 
                              V_SOON_CINEMA
                              WHERE
                              MOVIE_STATE = '$arg_movieState'
                              AND
                              (PICTURE_TYPE ='$arg_pictureType'
                               OR PICTURE_TYPE ='封面')
                              )
                       WHERE rownumber BETWEEN '$pageStar' AND '$pageEnd'
                       ORDER BY PICTURE_RELATE_ID DESC


2.先排序,再分页

             

               以下是先对表进行排序搜索,如搜索出来的结果是: 

                  a.在100条数据中的先倒序排列得到数据集合B

                  b.再对集合B从中搜索出前10条来

    SELECT * FROM
                       (SELECT
                        vsc.MOVIE_UID AS PICTURE_RELATE_ID,
                        vsc.TITLE AS HOT_MOVIE_CACHE_NAME,
                        vsc.PICTURE_PATH,
                        vsc.START_TIME AS DATEINDATE_IN,
                        PICCACHEPATH,
                        ROWNUM row_num from
                        (SELECT MOVIE_UID,TITLE,PICTURE_PATH,START_TIME,PICCACHEPATH FROM V_SOON_CINEMA vs
                        WHERE
                        MOVIE_STATE = '$arg_movieState'
                        AND
                        (PICTURE_TYPE ='$arg_pictureType'
                         OR PICTURE_TYPE ='封面')
                        ORDER BY vs.MOVIE_UID DESC) vsc
                        WHERE ROWNUM<='$pageEnd'
                        )vsca WHERE vsca.row_num >= '$pageStar'"

3.sql  to_char 与to_timestamp 例子

SELECT CONCAT('¥',PRICE_STANDARD) as PRICE,to_char(SHOW_DETAIL_TIME,'HH24:MI') as SHOWTIME,
              SHOW_DATE,to_char(SHOW_DATE,'yyyy-mm-dd') as STR_DATE
              FROM V_SHOW_FILM_CINEMA
              WHERE FILM_UID = '$arg_moveId'
              AND SHOW_DETAIL_TIME > to_timestamp('$nowTime','yyyy-mm-dd HH24:mi:ss')
              ORDER BY SHOW_DATE,SHOWTIME


4.sql not exist 与not in

                not in 当T_GROUP_CINEMA表没数据时,下面搜索不出数据
                相当于select ....not in(null)

SELECT DISTINCT T_CINEMA.CINEMA_ENTITY_ID,T_CINEMA.CINEMA_NAME
        FROM T_CINEMA,T_GROUP_CINEMA
        WHERE
        T_CINEMA.CINEMA_ENTITY_ID 
        not in(SELECT CINEMA_ENTITY_ID FROM T_GROUP_CINEMA);


          当T_GROUP_CINEMA表没数据依然可以查询出数据来

select T_CINEMA.CINEMA_ENTITY_ID,T_CINEMA.CINEMA_NAME 
from T_CINEMA
where not exists 
(select 1 
        from T_GROUP_CINEMA 
        where 
        T_GROUP_CINEMA.CINEMA_ENTITY_ID=T_CINEMA.CINEMA_ENTITY_ID 
)


   



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值