Mysql sql語句大全

來源:互聯網
上載者:User

標籤:from   class   ping   說明   logs   建立資料庫   delete   ica   插入   

Mysql sql語句大全

1、說明:建立資料庫   create database  dbname;

2、說明:刪除資料庫   drop database dbname;

3、說明:建立新表      create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..);

4、說明:刪除新表  drop table tabname;

5、說明:增加一個列   Alter table tabname add column col type;

6、說明:幾個簡單的基本的sql語句
  選擇:select * from table1 where 範圍;
  插入:insert into table1(field1,field2) values(value1,value2);
  刪除:delete from table1 where 範圍;
  更新:update table1 set field1=value1 where 範圍;
  尋找:select * from table1 where field1 like ’%value1%’ ---like的文法很精妙,查資料!;
  排序:select * from table1 order by field1,field2 [desc];
  總數:select count as totalcount from table1;
  求和:select sum(field1) as sumvalue from table1;
  平均:select avg(field1) as avgvalue from table1;
  最大:select max(field1) as maxvalue from table1;
  最小:select min(field1) as minvalue from table1;

7、左串連:

  左串連即:返回左邊表中所有被查詢欄位+右邊表中合格欄位。  

select stu.id,stu.name,stu.classe_name,tech.id,tech.name FROM stu LEFT JOIN tech on stu.classe_name=tech.classe_name;

 

  下面是兩張表:

  表stu

  

  表tech

  

  結果如下:

8、內串連:

  返回表中合格條目。

SELECT stu.id,stu.name,stu.classe_name,tech.id,tech.name FROM stu INNER JOIN tech on stu.classe_name=tech.classe_name;

結果如下:

9、右串連:   返回右邊表中所有被查詢欄位+左邊表中合格欄位。
SELECT stu.id,stu.name,stu.classe_name,tech.id,tech.name FROM stu RIGHT JOIN tech on stu.classe_name=tech.classe_name;

  結果如下:

 

 

 

Mysql sql語句大全

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.