DB/SQL/ͱƤ

Top / DB / SQL / ͱƤ

ꤷɽ顢ꤷФʼͱơˡ

  • ˡ
    -- piyo ɽƤ
    select * from piyo;
    
    -- piyo ɽ hoge 
    select hoge from piyo;
    
    -- piyo ɽ hoge  fuga 
    select hoge, fuga from piyo;
    

Ԥ

ꤷɽ顢ꤷԤФˡ

  • ˡ
    -- ܤϤ
    select hoge from piyo where <>
    
    -- Ȥ黻ҤϤʤΡʸ select  from  Ͼά
    where fuga = 'hoge'  -- fuga ʸ hoge
    where fuga = 100     -- fuga  100
    where fuga > 100     -- fuga  100 礭
    where fuga >= 100    -- fuga  100 ʾ
    where fuga < 100     -- fuga  100 꾮
    where fuga <= 100    -- fuga  100 ʲ
    where fuga <> 100    -- fuga  100 ǤϤʤ
    
    -- ΤȤ
    -- 줾 not Ф줾ξ꤬Ȥ
    where fuga [not] between 100 and 200            -- fuga  100  200 δ
    where fuga [not] in ('hoge', 'fuga', 100, 200)  -- fuga  "hoge""fuga"100200 Τ줫
    where fuga [not] like '_b%'                     -- fuga  2 ʸܤ "b"
    where fuga [not] like '%HOGE\_%' escape '\'     -- fuga  "HOGE_" ޤ
    where fuga is [not] null                        -- fuga  null
    
    -- ޤȤʤʥѥ
    -- 䤤碌λ˻Ȥ
    -- 줾 not ˤʤ
    where fuga > [not] any (100, 200, 300)  -- fuga  100  200  300 Τɤ줫礭
    where fuga < [not] any (100, 200, 300)  -- fuga  100  200  300 Τɤ줫꾮
    where fuga = [not] any (100, 200, 300)  -- fuga  100  200  300 Τɤ줫IN Ʊ
    where fuga > [not] all (100, 200, 300)  -- fuga  100  200  300 Τ٤Ƥ礭
    where fuga < [not] all (100, 200, 300)  -- fuga  100  200  300 Τ٤Ƥ꾮
    
    -- ʣ and ⤷ or̤ͥϥåǻǽ
    -- ̾ and ͥ衣
    where fuga > 100 and fuga < 200
    where fuga > 100 and ( fuga < 200 or foo < 100 )
    
    • like üʸΰ̣ϤʡüʸΤΤ򸡺Ȥ escape
      ̣
      %0ʸʾǤդʸ
      _1ʸǤդʸ

̾Ĥ

Ф̾դ롣̤ɽ̾ꤹۤȤʸҡˤˤȤ롣

  • ˡ
    -- ֥륯ȤǰϤʸʸ̡ξ fuga ˤʤ
    select hoge as "fuga" from piyo;
    
    -- ϤޤʤʸFUGA
    select hoge as fuga from piyo;
    
    -- as Ͼάǽ
    select hoge "fuga" from piyo;
    select hoge fuga from piyo;
    

Ϣ뤹

Ϥ򹥤Ϣ뤷롣

  • ˡ
    -- ñˤäĤƽϤ
    select hoge || fuga from piyo;
    
    -- ֤˲ʸȤϥ󥰥륯
    select hoge || ' is a ' || fuga from piyo;
    

Ԥνʣʤ

ƱԤäѤäԤˤޤȤ롣

  • ˡ
    -- ܤϤ
    select distinct hoge from piyo;
    
    --  hoge  fuga ȤǽʣʤǤνʣӽԲ
    select distinct hoge, fuga from piyo;
    

Ԥ򥽡Ȥ

ϤԤ褯¤٤롣

  • ˡ
    -- ܤϤhoge ǥȡʾ
    select hoge, fuga from piyo order by hoge;
    
    -- ˥ȡʥǥեȡ
    order by hoge asc
    
    -- ߽˥
    order by hoge desc
    
    -- ʣꤷƥȡǤ fuga ˥Ȥ줿֤ hoge ¤
    order by hoge, fuga
    
    -- Ⱦˤ̾Ѳǽ
    select hoge as fuga from piyo order by fuga;
    

Last-modified: 2011-10-17 () 20:04:52 (2286d)