<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      mysql基本語法

      [摘要]今天我們來說一下有關mysql的基本語法,通過學習掌握這些語法,我們就可以對數據庫做一些簡單的基本操作了。-- 增,刪,改 insert delete update -- 增 必須向所有列填充...
      今天我們來說一下有關mysql的基本語法,通過學習掌握這些語法,我們就可以對數據庫做一些簡單的基本操作了。


      -- 增,刪,改 insert delete update

      -- 增 必須向所有列填充數據,除了(自增列,有默認值列,允許為空)可以不填充
      INSERT [INTO] 表(列列表) values (值列表)


      -- 刪
      DELETE from 表[where 條件]
      DELETE from student

      -- 改
      UPDATE 表 set 列 = 值,列 = 值 [where 條件]
      update student set name = '張亮',set sex = '女' where studentno = '4'

      -- 查詢 模糊查詢 分頁
      like between in is null


      -- 查詢 排序 分組 連接
      -- 排序 order by 默認是升序:asc 降序:desc
      -- 按多個列來排序,先按第一個字段排序,在此基礎上再按第二個字段進行排序.
      select * from student order by age,studentno
      -- 分組 聚合函數 sum avg max min count
      select sum(age),avg(age),max(age),min(age) from student;
      -- count 是統計有多少數據行,如果是統計某個列,則會忽略列中的NULL值。
      select count(email) from student
      -- 統計有多少學生沒有錄入郵箱信息??
      select count(*) from student where email is null


      -- 分組,group by 是把數據進行分類再匯總,必須要配合聚合函數使用,
      -- 關鍵點:按什么進行分組,用什么聚合函數進行統計。
      -- 如果某個列出現在from關鍵字前,且沒有包含在聚合函數中,則此列必須出現在group by 子句中
      -- 統計每個年級有多少學生?
      select gradeId,count(*) from student group by gradeId
      -- 統計每個年級男女學生各有多少? 按年級和性別進行分組,用count函數
      select gradeid,sex,count(*) from student group by sex,gradeId;
      -- 統計每個年級有多少課時?
      select gradeid,sum(classHours) from subject group by gradeid
      -- 統計每個年級有多少課程?
      select gradeid,count(*) from subject group by gradeid
      -- 統計每個學生的總成績和平均成績?
      select studentno,sum(result),avg(result) from score group by studentno


      -- 連接查詢 內連接 外連接 交叉連接
      -- 當數據來自兩個或兩個以上的表時,則才用連接查詢來實現。
      -- where 條件是兩個表的主鍵列相等。
      select * from student s,grade g where s.gradeid=g.gradeid
      -- 建議使用下面的寫法,性能好一些。
      select * from student s inner join grade g on s.gradeid=g.gradeid
      -- 查詢姓名,學號、課程名、分數 數據來自于3個表?
      select name,s.studentno,subjectname,result from student s
      inner join score c on s.studentno = c.studentno
      inner join subject j on c.subjectno= j.subjectno


      -- 外連接 左外連接 右外連接
      /* 左外連接,在前面的表是主表,后面的表是子表,主表的數據全部顯示,
      再用子表的數據進行填充,如果子表中沒有對應的數據,則用NULL來填充 */
      select * from student s
      left join score c on s.studentno = c.studentno


      -- 查詢有哪些學生沒有參加過考試,用左外連接實現??
      select * from student s
      left join score c on s.studentno = c.studentno
      where c.studentno is null
      -- 查詢哪些學生沒有參加考試,用子查詢實現??
      -- 子查詢的結果只能是返回一列值,返回的值如果有多個,就只能用in 不能用 =
      select * from student where studentno
      not in( select studentno from score)

      以上就是在Mysql中對表做一些簡單的基礎操作內容,希望對大家有幫助。

      相關文章

      MySql基本語法(學習筆記)_MySQL

      了解mysql基本語法

      以上就是mysql基本語法的詳細內容,更多請關注php中文網其它相關文章!


      學習教程快速掌握從入門到精通的SQL知識。




      日韩精品一区二区三区高清