小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

select 1 from 淺析

 悟靜 2012-06-10

今天看到項(xiàng)目代碼里有這條語句,不懂select 1 from XXXXXXX里的1是何意,查了一番才知道:

1、select 1 from mytable;與select anycol(目的表集合中的任意一行) from mytable;與select * from mytable 作用上來說是沒有差別的,都是查看是否有記錄,一般是作條件用的。select 1 from 中的1是一常量,查到的所有行的值都是它,但從效率上來說,1>anycol>*,因?yàn)椴挥貌樽值浔怼?/P>

2、查看記錄條數(shù)可以用select sum(1) from mytable;等價(jià)于select sum(*) from mytable;

3、實(shí)際項(xiàng)目SQL:

select c_insrnc_cde, c_nme_cn
   from t_prd_ins a
where a.c_prod_no = '01'
    and not exists
(select 1
           from (select d.c_insrnc_cde, a.c_nme_cn
                   from t_prd_ins                   a,
                        tb_bas_ply_policy_rdr       c,
                        tb_bas_ply_policy_rdr_list d
                  where a.c_insrnc_cde = d.c_insrnc_cde
                    and d.c_policy_id = c.c_policy_id
                    and d.c_seq_no = c.c_seq_no
                    and a.c_kind_no = '01'
                    and c.c_dpt_cde = '101'   ----機(jī)構(gòu)樹中取出機(jī)構(gòu)
                    and c.c_prod_no = '01'
                    and c.t_effc_tm <= TO_DATE('2007-9-5', 'YYYY-MM-DD')
                    and c.t_expd_tm >= TO_DATE('2007-9-5', 'YYYY-MM-DD')
                    and c.c_work_mode = '00501'
                    and c.c_reach_area = '00701'
                    ) t
          where t.c_insrnc_cde = a.c_insrnc_cde);

 二、http://blog.csdn.net/wangyihust/archive/2009/02/05/3863758.aspx

測試場景:(轉(zhuǎn)自網(wǎng)絡(luò)文獻(xiàn))
table表是一個(gè)數(shù)據(jù)表,假設(shè)表的行數(shù)為10行。

1:select  1 from table       增加臨時(shí)列,每行的列值是寫在select后的數(shù),這條sql語句中是1

2:select count(1)  from table   不管count(a)的a值如何變化,得出的值總是table表的行數(shù)

3:select sum(1) from table   計(jì)算臨時(shí)列的和

 在SQL SERVER中用 1 測試了一下,發(fā)現(xiàn)結(jié)果如下:

1:測試結(jié)果,得出一個(gè)行數(shù)和table表行數(shù)一樣的臨時(shí)列(暫且這么叫,我也不知道該叫什么),每行的列值是1;

2:得出一個(gè)數(shù),該數(shù)是table表的行數(shù);

3:得出一個(gè)數(shù),該數(shù)是table表的行數(shù);

然后我又用“2”測試,結(jié)果如下:

1:得出一個(gè)行數(shù)和table表行數(shù)一樣的臨時(shí)列,每行的列值是2;

2:得出一個(gè)數(shù),該數(shù)是table表的行數(shù);

3:得出一個(gè)數(shù),該數(shù)是table表的行數(shù)×2的數(shù)

然后我又用更大的數(shù)測試:

1:得出一個(gè)行數(shù)和table表行數(shù)一樣的臨時(shí)列,每行的列值是我寫在select后的數(shù);

2:還是得出一個(gè)數(shù),該數(shù)是table表的行數(shù);

3:得出一個(gè)數(shù),該數(shù)是table表的行數(shù)×寫在select后的數(shù)

    綜上所述:第一種的寫法是增加臨時(shí)列,每行的列值是寫在select后的數(shù);第二種是不管count(a)的a值如何變化,得出的值總是table表的行數(shù);第三種是計(jì)算臨時(shí)列的和。
 

 

 

 

語句if not exists(select 1 from deleted d join inserted i on d.ID=i.ID
and d.col1=1 and i.col1=2)

if not exists 如果不存在
(..)這里該是驗(yàn)證更新,更新前的id等于更新后的id,并且更新前col的值是1,更新后的值是2

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多