亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Mysql的DQL查詢操作全面分析講解

 更新時(shí)間:2022年12月03日 10:01:35   作者:coleak  
DQL(Data Query Language 數(shù)據(jù)查詢語(yǔ)言):用于查詢數(shù)據(jù)庫(kù)對(duì)象中所包含的數(shù)據(jù)。DQL語(yǔ)言主要的語(yǔ)句:SELECT語(yǔ)句。DQL語(yǔ)言是數(shù)據(jù)庫(kù)語(yǔ)言中最核心、最重要的語(yǔ)句,也是使用頻率最高的語(yǔ)句

DQL簡(jiǎn)介

概念:DQL(data query language)數(shù)據(jù)查詢語(yǔ)言 select操作

排序規(guī)則:

- select 表達(dá)式1|字段,.... - from 表名 where 條件 - group by 列名 - having 條件 - order by 列名 asc|desc - limit 位置,數(shù)量

語(yǔ)法結(jié)構(gòu):

    SELECT [ALL | DISTINCT] ALL表示查詢出所有的內(nèi)容 DISTINCT 去重
            {* | 表名.* | 表名.字段名[ AS 別名][,...]} 指定查詢出的字段的
        FROM
            表名[AS 別名][,表1... AS 別名]
        [INNER | [LEFT | RIGHT] [OUTER] JOIN 另一張表名 [AS 別名] ON 關(guān)聯(lián)條件]
        [WHERE 條件]
        [GROUP BY 分組字段[,...]] 
        [HAVING 給分組后的數(shù)據(jù)進(jìn)行條件篩選]
        [ORDER BY 排序字段[,...]]
        [LIMIT [startIndex,]pageSize]

具體操作

數(shù)據(jù)準(zhǔn)備

create database if not exists test;
use test;
create table if not exists data(
id tinyint primary key auto_increment,
price double NOT null,
name varchar(20) not null,
type varchar(20) not null)
;
insert into data values
(null,900,'洗衣機(jī)','b'),
(null,1900,'冰箱','b'),
(null,2900,'空調(diào)','b'),
(null,3900,'電視','b'),
(null,150,'衣服','c'),
(null,180,'褲子','c'),
(null,200,'鞋子','c'),
(null,188,'洗面奶','a'),
(null,188,'洗發(fā)水','a'),
(null,199,'洗衣液','a'),
(null,88,'沐浴露','a'),
(null,5,'泡面','d'),
(null,15,'餅干','d'),
(null,30,'咖啡','d');

簡(jiǎn)單查詢

select * from data;
select name,price from data;
select * from data as d;
select * from data d;
select d.name,d.price from data d;
select  distinct price from data;
select name,price +100 newprice from data;

運(yùn)算符

算術(shù)運(yùn)算符

select name,price *1.5 newprice from data;

條件查詢

select * from data where name='洗衣機(jī)';
select * from data where  !(price>100);
select * from data where price between 200 and 1000;
select * from data where price in(188,900);
-- 等于下面兩句
select * from data where price = 188 or price =900;
select * from data where price = 188 || price =900;
select * from data where name like '%衣%';
select * from data where name like '衣%';
select * from data where name like '_衣%';
select * from data where id is null;

注釋:當(dāng)有NULL作為比較大小的對(duì)象時(shí),最大值和最小值均為null

排序查詢

select * from data order by price;
select * from data order by price desc;
select distinct price from data order by price desc;
select * from data order by price,id;

聚合查詢

select count(*) from data;
-- 不全為空的行數(shù)
select count(id) from data;
-- 通過(guò)主鍵值查詢行數(shù)
select count(*) from data where price<200;
select sum(price) from data where type='A';
select max(id) from data;
select min(price) from data;
select max(price) max_price,min(price) min_price from data;
select avg(price) from data where type='c';

null值的處理

分組查詢

select sum(price) from data group by type;
select type,count(id) from data group by type;

條件篩選

select type,count(id) count from data group by type having count=4 order by type;

分頁(yè)查詢

分頁(yè)顯示

select * from data limit 5;
-- 從第四條開(kāi)始依次向后顯示五條
select * from data limit 3,5;

insert into select語(yǔ)句

create table data2(
name varchar(10),
price double);
insert into data2 select name,price from data;
select * from data2;
create table data3(
type varchar(10),
num int
);
insert into data3 select type,count(*) from data group by type order by count(*);
select * from data3;

總結(jié)

到此這篇關(guān)于Mysql的DQL查詢操作全面分析講解的文章就介紹到這了,更多相關(guān)Mysql DQL查詢內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • mysql動(dòng)態(tài)游標(biāo)學(xué)習(xí)(mysql存儲(chǔ)過(guò)程游標(biāo))

    mysql動(dòng)態(tài)游標(biāo)學(xué)習(xí)(mysql存儲(chǔ)過(guò)程游標(biāo))

    mysql動(dòng)態(tài)游標(biāo)示例,通過(guò)準(zhǔn)備語(yǔ)句、視圖和靜態(tài)游標(biāo)實(shí)現(xiàn),大家參考使用吧
    2013-12-12
  • MySQL尾部空格處理方法詳解

    MySQL尾部空格處理方法詳解

    這篇文章主要介紹了MySQL尾部空格處理方法詳解的相關(guān)資料,通過(guò)創(chuàng)建合適的索引來(lái)實(shí)現(xiàn)區(qū)分有尾部空格和沒(méi)有尾部空格的字符串,需要的朋友可以參考下
    2023-07-07
  • MySQL學(xué)習(xí)之索引及優(yōu)化

    MySQL學(xué)習(xí)之索引及優(yōu)化

    這篇文章主要介紹MySQL的索引及優(yōu)化,索引是幫助MySQL進(jìn)行高效查詢的一種數(shù)據(jù)結(jié)構(gòu)。好比一本書(shū)的目錄,能加快查詢的速度,想進(jìn)一步了解的小伙伴可以詳細(xì)閱讀本文
    2023-03-03
  • MySQL數(shù)據(jù)庫(kù)優(yōu)化之分表分庫(kù)操作實(shí)例詳解

    MySQL數(shù)據(jù)庫(kù)優(yōu)化之分表分庫(kù)操作實(shí)例詳解

    這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)優(yōu)化之分表分庫(kù)操作,結(jié)合實(shí)例形式詳細(xì)分析了mysql數(shù)據(jù)庫(kù)分表分庫(kù)垂直拆分、水平拆分相關(guān)原理以及應(yīng)用案例,需要的朋友可以參考下
    2020-01-01
  • 淺談MySQL在cmd和python下的常用操作

    淺談MySQL在cmd和python下的常用操作

    下面小編就為大家?guī)?lái)一篇淺談MySQL在cmd和python下的常用操作。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • my.cnf參數(shù)配置實(shí)現(xiàn)InnoDB引擎性能優(yōu)化

    my.cnf參數(shù)配置實(shí)現(xiàn)InnoDB引擎性能優(yōu)化

    目前來(lái)說(shuō):InnoDB是為Mysql處理巨大數(shù)據(jù)量時(shí)的最大性能設(shè)計(jì)。它的CPU效率可能是任何其它基于磁盤的關(guān)系數(shù)據(jù)庫(kù)引擎所不能匹敵的。在數(shù)據(jù)量大的網(wǎng)站或是應(yīng)用中Innodb是倍受青睞的。另一方面,在數(shù)據(jù)庫(kù)的復(fù)制操作中Innodb也是能保證master和slave數(shù)據(jù)一致有一定的作用。
    2017-05-05
  • Ubuntu16.04安裝mysql5.7.22的圖文教程

    Ubuntu16.04安裝mysql5.7.22的圖文教程

    這篇文章主要介紹了Ubuntu16.04安裝mysql5.7.22的圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • 深入解析mysql中order by與group by的順序問(wèn)題

    深入解析mysql中order by與group by的順序問(wèn)題

    本篇文章是對(duì)mysql中order by與group by的順序問(wèn)題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • MySQL百萬(wàn)級(jí)數(shù)據(jù),怎樣做分頁(yè)查詢

    MySQL百萬(wàn)級(jí)數(shù)據(jù),怎樣做分頁(yè)查詢

    這篇文章主要介紹了MySQL百萬(wàn)級(jí)數(shù)據(jù),怎樣做分頁(yè)查詢?今天咱們就來(lái)聊聊這個(gè)話題,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • mysql數(shù)據(jù)插入覆蓋和時(shí)間戳的問(wèn)題及解決

    mysql數(shù)據(jù)插入覆蓋和時(shí)間戳的問(wèn)題及解決

    這篇文章主要介紹了mysql數(shù)據(jù)插入覆蓋和時(shí)間戳的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03

最新評(píng)論