MySQL自用笔记

Posted SK特困生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL自用笔记相关的知识,希望对你有一定的参考价值。


This browser does not support music or audio playback. Please play it in Weixin or another browser.


https://www.bilibili.com/video/BV1UE41147KC?p=4
mysql windows 安装教程

安装官网:mysql.com

MySQL自用笔记(1)




第一课


USE sql_store;#使用这个数据库


#sql中大小写是不区分的,最好用大写

-- select * #选取数据库(*可以返回所有行)

-- from customers

-- where customer_id=1 #如果加上了 -- 这一句就会被省略

-- order by first_name #按照首字母排序


#这些语句都是有顺序的(select-from-where-order by)


select 1, 2; #选取这两个数字


select*from customers;

#对于简单查询来说是可以这样的,但是最好放两行


注意运行完一条需要加;分隔开来




第二课:select 语句


select first_name,last_name

from customers;


select last_name,first_name,points,points+10 #数字计算式

from customers;


select #可以分行表示!注意运算顺序

    last_name,

    first_name,

    points,

    points*10+100 as "discont factor" #用as取别名,想要插入空格的话,就要用引号

from customers;


select state #distinct 可以移除重复项

from customers;




第三课:where语句


select*

from customers

where state<>"VA";

# > < >= <= = != <>

#字符串是一串字符序列,需要加引号

 

 select*

from customers

where birth_date>"1990-01-01";





第四课:and or not


select*

from customers

where birth_date>"1990-01-01" and points >1000;


select*

from customers

where birth_date>"1990-01-01" or points >1000;


select*

from customers

where birth_date>"1990-01-01" or 

(points >1000 and state="va");


#运算顺序:and>or


select*

from customers

where not (birth_date>"1990-01-01" or points >1000);


#上下这两种是一个意思哟!


select*

from customers

where (birth_date<="1990-01-01" and points <= 1000);


#练习题

-- from the order_items table, get the items

-- for order#6

-- where the total price is greater than 30


select *

from order_items

where quantity*unit_price>=30 and order_id=6;




第五课-in

 

select *

from customers

where state = "va" or state='fl' or state='ga';

#sql中不能连接字符串和布林


select *

from customers

where state not in ('va','fl','ga');


#exercise:return products with

-- quantity in stock equal to 49,38,72


select*

from products

where stock in (49,38,72);



gavin:“为什么最近内容这么干?”

suki:“因为我想水一水MySQL自用笔记(1)

欢迎大家踊跃投稿~

(图片和文字都可!)

投稿可加vx:w986450113

有建议也可加vx私聊~


喜欢的话点个“赞”和“在看”呗~


关注我,在SK一起成长和交流吧!


后台回复“MySQL”可以获取练习材料

一起来卷吧~

以上是关于MySQL自用笔记的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript笔记(自用)——02语法

自用RNN+LSTM笔记

JavaScript笔记(自用)——03变量(varletconst)

JavaScript笔记(自用)——01什么是JavaScript

JavaScript笔记(自用)——01什么是JavaScript

Linux 笔记(自用)