• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            The Fourth Dimension Space

            枯葉北風寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢令

            數據庫練習

            計算兩日期間隔天數
            values (days(current date) - days('2014-09-01'))

            去出某一字符串的的一個單詞,空格為分隔符
            select substr(title,1,instr(title,' ')-1) from titles

            將字符串的一個空格替換為'--hello--'
            select substr(title,1,locate(' ',title)-1)  || '--hello--' ||  substr(title,locate(' ',title)+1) from titles

            db2生成隨機數
            select case when price is null then INT(rand()*100) else price end from titles

            兩日期相差多少月,64代表月。參數可以更改求出周,小時等等。
            select TIMESTAMPDIFF(64,char(TIMESTAMP(CURRENT DATE) - TIMESTAMP(pubdate)) )from titles

            有關db2日期操作可參考此博客。
            http://www.cnblogs.com/wanghonghu/archive/2012/05/25/2518604.html

            建立數據表,有generated always列
            create table t1
            (
            c1 char(30),
            c2 double,
            c3 int not null generated always as identity
                  (start with 100, increment by 5)
            )
            第一次更新用insert into t1(c1,c2,c3) values('123',34,default)
            以后用 insert into t1(c1,c2) values('hi',45)

            如果是generated by default
            create table t1
            (
            c1 char(30),
            c2 double,
            c3 int not null generated by default as identity
            (start with 100, increment by 5)
            )
            如果插入時只有兩個參數,就按默認的來
            如果三個參數,就是插入的那個數
            默認生成的第三個數可以修改,系統會有記錄,即使修改了也會從上一次的默認位置開始疊加。不會再回到100.

            --select * from authors

            --select au_lname, au_fname from authors where state ='CA'

            --select * from publishers

            --select distinct state from publishers

            --select *from titles

            --select * from titles where price is null

            -- select case when price is null then 0 else price end from titles-- it works!!!!!!!!!!

            -- 4 Functions

            --select varchar_format(current date - date('2011-01-01') + date, 'DD-MM-YY') as newDate,

            -- varchar_format(date,'DD-MM-YY') as olddate from sales

            --values current date - date('2014-01-01') + date('2014-01-02')

            --select *from roysched

            --select hex(lorange) from roysched

            --select * from titles where price in (20,19) -- in one shot ZANZANZANZANZAN!!!

            select case type when 'business' then Title else 'other' end from titles 聯系條件語句并顯示成不同的屬性

            -----------------------------------------------------------------------------------------------

            --select * from authors

            --select au_lname, au_fname from authors where state ='CA'

            --select * from publishers

            --select distinct state from publishers

            --select *from titles

            --select * from titles where price is null

            -- select case when price is null then 0 else price end from titles-- it works!!!!!!!!!!

            -- 4 Functions

            --select varchar_format(current date - date('2011-01-01') + date, 'DD-MM-YY') as newDate,

            -- varchar_format(date,'DD-MM-YY') as olddate from sales

            --values current date - date('2014-01-01') + date('2014-01-02')

            --select *from roysched

            --select hex(lorange) from roysched

            --select * from titles where price in (20,19) -- in one shot ZANZANZANZANZAN!!!

            --select case type when 'business' then Title else 'other' end from titles

            --select syscolumns.length from syscolumns where syscolumns.id = 'titles' and syscolumns.name = 'title'

            --5 Grouping

            --select (days(max(pubdate)) - days(min(pubdate)) )/365 from titles

            --select title from titles order by length(title)

            --select *from titles

            --select count(*) from authors group by city

            --select title from titles where length(title) = (select max(length(title)) from titles)

            --select coalesce(price,0) from titles -- yuan lai bushi yong is null shi yong zhe ge a!!!!

            --select length(price) from titles

            /*

            select title from titles where length(title) >= all

            (

            select length(title) from titles

            )

            */

            --select pubdate from titles

            /*

            select title,pubdate from titles where pubdate >= all

            (

            select pubdate from titles

            )

            */

            --select count(*) from sales group by stor_num

            --select * from sales

            --select * from publishers

            --select * from titles as a inner join publishers as b on a.pub_id = b.pub_id

            --select title,city,a.pub_id from titles as a inner join publishers as b on a.pub_id = b.pub_id where city not in ('Boston')

            --select * from psales

            /*

            select b.ord_num,b.discount,d.discounttype from psales as a inner join salesdetail as b on a.stor_id = b. stor_id and a.ord_num = b.ord_num

            inner join stores as c on a.stor_id = c.stor_id inner join discounts as d on c.stor_id = d.stor_id order by b.ord_num

            */

            --select * from authors

            --select * from publishers

            --select * from authors as a inner join publishers as b on a.city = b.city

            --select sum(qty) from salesdetail

            --select pub_name, count(distinct type) from publishers as a inner join titles as b on a.pub_id = b.pub_id group by pub_name

            --select *from titleauthor

            --7 Sub-Queries

            /*

            select pub_name from publishers where pub_id in

            (

            select pub_id from titles

            )

            */

            --select * from publishers

            --nice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            /*

            select type,title,t1.price

            from titles as t1

            where price > (select avg(price) from titles as t2 where t2.type = t1.type)

            */

            -- nice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

             

            select title,t1.price

            from titles as t1

            where price > all(select coalesce(price,0) from titles as t2 where t2.type != t1.type)

             

            --select * from titles

            --select t1.type,t1.title,t1.price,(select avg(price) from titles as t2 where t2.type = t1.type)

            --from titles as t1

            --where price > (select avg(price) from titles as t2 where t2.type = t1.type)

             

            --select avg(price) from titles

            --select abs(13.93750000000000000000000000- price) from titles

            --select coalesce(abs((select avg(price) from titles) - price),0) from titles


            --select count(*) as ANS from SB_AUCTION where (days(enddate) - days(startdate) < 10)

            /*

            select description, enddate, reserve from SB_Auction inner join sb_item on SB_Auction.itemid = sb_item.itemid

            where (date('2011-02-20') >= startdate and date('2011-02-20') <= enddate) order by reserve desc

            */

             

            --select * from sb_bid

            --select name from (sb_bid as a inner join sb_auction as b on a.bidder = b.userid) inner join sb_user as c on b.userid = c.userid group by name

            --select * from authors

            --select newA.name from

            --(

            --select name,c.itemid from (sb_user as a inner join sb_auction as b on a.userid = b.userid)

            -- inner join sb_item as c on b.itemid = c.itemid

            --) AS newA

            --select * from sb_auction

            /*

            create view weitaol_view

            as

            select c.auctionid, max(amount) as winning_bid from sb_auction as a inner join sb_user as b on a.winnerid = b.userid

            inner join sb_bid as c on a.auctionid = c.auctionid where a.state = 'sold' group by c.auctionid

            */

            --select * from weitaol_view

             

            select enddate, description,coalesce(name,'==') as name ,coalesce(c.winning_bid,0) as winning_bid

            from sb_auction as a inner join sb_item as b on a.itemid = b.itemid

            left join sb_user on a.winnerid = sb_user.userid

            left join weitaol_view as c on a.auctionid = c.auctionid

            /*

            select * from sb_auction

            */




            posted on 2014-10-15 23:39 abilitytao 閱讀(448) 評論(0)  編輯 收藏 引用

            91精品久久久久久无码| 一本色道久久HEZYO无码| 91精品国产91久久久久久| 91性高湖久久久久| 亚洲七七久久精品中文国产 | 日韩亚洲欧美久久久www综合网 | 国产精品99久久久久久董美香| 久久美女人爽女人爽| 久久精品国产亚洲αv忘忧草| 色欲久久久天天天综合网| 精品人妻伦九区久久AAA片69 | 97精品国产97久久久久久免费| 69久久精品无码一区二区| 久久久久亚洲爆乳少妇无| 亚洲愉拍99热成人精品热久久| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 国产亚洲美女精品久久久| 亚洲国产精品无码久久久秋霞2| 日韩亚洲欧美久久久www综合网| 亚洲日本va中文字幕久久| 久久久久久久综合日本| 久久99国产精品久久99| 久久久女人与动物群交毛片| 久久精品国产亚洲一区二区三区 | 精品久久人人妻人人做精品| 97久久精品人妻人人搡人人玩| 国产成人久久精品一区二区三区 | 奇米综合四色77777久久| 日韩AV毛片精品久久久| 精品国产婷婷久久久| 韩国三级大全久久网站| 国产精品久久午夜夜伦鲁鲁| 少妇久久久久久久久久| 熟妇人妻久久中文字幕| 久久久久人妻精品一区| 久久综合亚洲欧美成人| 久久久久亚洲av无码专区| 亚洲日韩中文无码久久| 久久国产精品99国产精| 久久久久久久久无码精品亚洲日韩| 97精品伊人久久大香线蕉|