国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

數(shù)據(jù)庫語法03

2019-11-14 16:18:13
字體:
供稿:網(wǎng)友

SQL一些基礎(chǔ)的命令

    插入數(shù)據(jù)

Insert into Persion1(Name,Age)  Values(‘zhanghui’,21);

用newid自動生成序號。

Insert into Persion2(Id,Name,Age) Values(newid(),’hui’,22);

  更新數(shù)據(jù)

1: UPDATE T_Person1 set Age=30;

2: Update Person set Name=’xiaohui’

Where Age>=20;

**           在數(shù)據(jù)庫中等于號為一個等號。

**          “<>”:表示不等于;

**           或者:為or;

刪除數(shù)據(jù)

     刪除表全部

        Delete from Person1

     刪除表的數(shù)據(jù),表還在。

        Delete from Person1 where  Age>21

數(shù)據(jù)檢索

Select  *  from   <*:表示表名> 后面也可以加where 來區(qū)劃大小

其啟別名

     Select FName as 姓名,FAge as 年齡, FSalary as 月薪 from  Student

聚合函數(shù)

       Select count(*) from Student;  <總和>

       Select max(*) from Student;  

       Select sum(*) from Student;   <和>

排序

Select * from Student order by Age  ASC/DESC   <按年齡排序>       

    <ASC:從小到大;DESC:從大到小>

模糊匹配<通配符>

     *單字符通配符以‘_’,它匹配單個出現(xiàn)的字符。

以任意字符開頭,剩余部分為‘erry’:

     Select * from Student where FName like ‘_erry’

   *多字符匹配以‘%’,它匹配任意此數(shù)出現(xiàn)的字符。“K%”匹配以 K 開頭的字符串。

     Select * from Student where FNAme like ‘%n%’

**   在數(shù)據(jù)庫中的NULL為‘不知道’和C#中的解釋不一樣。不是沒有值。

image

數(shù)據(jù)的分組

按照年齡進行分組統(tǒng)計各個年齡斷的人數(shù):

     select FAge ,Count(*) from Student

     group by FAge

   **      group by 子句必須放在where語句之后。

   **      沒有出現(xiàn)group by子句中的列是不能放到select語句后的列名列表中的(聚合函數(shù)除外)

imageimage

  having語句

在where中不能使用聚合函數(shù),必須使用Having,Having必須位于Group by 之后。

  eg:

            select Name from ,count(*) as 人數(shù) from Student

            group by Name

            Having  count(*)>1       //Having 不能代替where,Having是對組進行過濾的。

image

 

限制結(jié)果集的行數(shù)

eg:    < 只取前3行>

       select top 3  * from Student

       order by  Name DESC

image

eg:    <只取去除5行的前3個>

select top 3 * from Student
where Name not in(select top 2* from Student order by Age DESC)
order by Age DESC

 

image     <.為什么出現(xiàn)錯誤???>

 

去除重復(fù)數(shù)據(jù)

eg:

    select Gender  from Student

       image

    select Gender, chinese from Student

      image

eg:    <加入distinct之后,去除重復(fù)>

      select distinct Gender,chinese  from Student

          image                       <distinct是對整個結(jié)果集進行數(shù)據(jù)重復(fù)處理的而不是針對每一列。> 

     select distinct Gender from Student

       image

 

數(shù)據(jù)庫的命令在不同的數(shù)據(jù)庫中是相同的,但只有掌握了最基礎(chǔ)的sql數(shù)據(jù)庫才能應(yīng)用于oclace等數(shù)據(jù)庫。雖然現(xiàn)在只是學(xué)習(xí)數(shù)據(jù)庫,但是我覺的還是挺有意思的,自己挺喜歡數(shù)據(jù)庫的。加油。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 治县。| 东源县| 镇巴县| 色达县| 定西市| 汽车| 武汉市| 瑞昌市| 武川县| 阿克陶县| 全南县| 朝阳区| 盐津县| 什邡市| 景谷| 绩溪县| 拜泉县| 冷水江市| 酒泉市| 江门市| 仁怀市| 高青县| 资阳市| 晋州市| 潼关县| 志丹县| 乌拉特中旗| 呼伦贝尔市| 金山区| 小金县| 鄂伦春自治旗| 田阳县| 万州区| 普陀区| 武义县| 页游| 大城县| 祁东县| 天气| 隆德县| 沅陵县|