亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    MYSQL-SELECT查-wx5c05455f3fc32的博客-51CTO博客

    SELECT語句的執(zhí)行過程(單表查詢)

    MYSQL-SELECT查-wx5c05455f3fc32的博客-51CTO博客過程如下 :

    1、先執(zhí)行FROM,先找表,先確定對應數(shù)據(jù)庫中的表

    SELECT

    SELECT [ALL | DISTINCT | DISTINCTROW ] [SQL_CACHE | SQL_NO_CACHE] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [FOR UPDATE | LOCK IN SHARE MODE]

    總結:

    1、字段顯示可以顯示別名count]:對查詢的結果進行輸出行數(shù)數(shù)量限制:單個任意字符

    示例:

    查找指定表中的所有字段

    seletc * from students

    查找students表中的所有數(shù)據(jù),顯示指定的行

    select * from students limit 6;

    查找指定字段行

    select name,age from students;

    查找tb1表中age 不等于24 的數(shù)據(jù)

    select * from stdents where age != 24;

    查找指定表中age大于等于24并且小于等于20的數(shù)據(jù)

    selsct * from students where age>=24 and age <=20; select * fromstudents where age between 20 and 24;

    查找指定表中age等于20或者等于24的數(shù)據(jù)

    select * from students where age=20 or age=24;

    查找指定表中的查詢出age 不在20到24的區(qū)間中的數(shù)據(jù)

    select * from students where age <25 or age >24; select * from students where not between 20 and 24;

    通過like 結合通配符進行模糊搜索

    查找所有字段開頭是s的任意長度數(shù)據(jù)

    select * frim students where name like 's%';

    查找所有字段開始是s,但是只有三個字符的數(shù)據(jù)

    select * from students where name like 's__'

    通過rlike結合正則表達式

    查找所有字段開頭是s的任意長度數(shù)據(jù)

    select * from students where name rlike ‘^s.*’

    查找指定字段匹配對應的條件,使用in關鍵字指定

    查找指定表中age 等于21 20 23 的數(shù)據(jù)

    select * from students where age in (20,21,23);

    查找指定表中age不等于21 20 23 的數(shù)據(jù)

    select * from students where age not in (20,21,23);

    對指定字段進行排序

    查找所有表數(shù)據(jù),并且指定字段進行排序

    查詢studentsd 的所有數(shù)據(jù),并指定age字段的值從大到小進行降序排序,如果多行之間的age字段相同時,在將name字段進行升序排序

    select * from students order by age desc, name asc;

    注意:

    order by 后面跟的要排序的字段,順序不一樣,結果也不一樣

    比如:

    1、select * from students order by age,classid; 2、select * from students order by classid,age; 第一條是先對age進行排序后,再對classid進行排序 第二條是先對classid進行排序,然后再對age進行排序

    去重

    使用DISTINCT關鍵字進行去重

    select distinct age from students;

    別名

    查詢時給字段添加別名,顯示的時候顯示別名

    select name as Name,age from students;

    分組

    分組

    GROUP:根據(jù)指定的條件把查詢結果進行“分組”以用于做“聚合”運算

    avg(),     統(tǒng)計最小值 max(),     統(tǒng)計最大值 min(),     統(tǒng)計最小值 count(),  統(tǒng)計每個分組的數(shù)量 sum() 統(tǒng)計每個分組的總和 HAVING: 對分組聚合運算后的結果指定過濾條件

    示例:

    對sudents表的gender字段進行分組

    select * from students group by gender;

    需要注意的是,顯示的是第一次查找到男生和女生數(shù)據(jù)

    MYSQL-SELECT查

    聚合操作

    select count(*),gender from students group by gender;

    先對性別進行分組,然后統(tǒng)計每組中的人數(shù)。

    count()就是一種聚合函數(shù),這個函數(shù)能統(tǒng)計數(shù)量

    先對性別進行分組,然后將每個分組中的age字段進行平均計算,得到每個組的平均年齡

    select avg(age),gender from students group by gender;

    MYSQL-SELECT查

    group_concat()用法

    select gender,group_concat(name) from students group by gender;先將性別分組后,然后顯示男生和女生組中的名字

    HAVING用法

    select gender,avg(age) from students group by gender having avg(age) &gt; 20;將分組過后的信息在進行條件過濾,

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號