SQL常用語句二

來源:互聯網
上載者:User

1、說明:複製表(只複製結構,源表名:a 新表名:b) (Access可用)
法一:select * into b from a where 1<>1
法二:select top 0 * into b from a

2、說明:拷貝表(拷貝資料,源表名:a 目標表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;

3、說明:in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)

4、說明:between的用法,between限制查詢資料範圍時包括了邊界值,not between不包括
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between 數值1 and 數值2

5.GROUP BY 是分組查詢, 一般 GROUP BY 是和 彙總函式配合使用,你可以想想

select A,count(B) 數量 from table group by A

6 having是對分組條件進行設定.當我們在用彙總函式的時候,一般都要用到GROUP BY 先進行分組,然後再進資料列彙總函式的運算。運算完後就要用到HAVING 的用法了,就是進行判斷了,例如說判斷彙總函式的值是否大於某一個值等等。
select customer_name,sum(balance)
from balance
group by customer_name
having balance>200;
這個是銀行資料庫的例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.