【MySQL80】:SQL语句-MySQL必知必会

1、了解数据库和表

# 展示所有数据库
show databases;
# 选择数据库
use testdb;
# 展示数据库对应的所有表
show tables;
# 展示某表所有的列
show columns from stock;
# 展示某表所有的列,快捷表达
describe stock;
# 其他show语句
show status;
show grants;
show errors;
########################################
select code from stock;
select code, close from stock;
select * from stock;
select distinct code from stock;
select distinct code from stock limit 10;
select distinct code from stock limit 2, 5;
select stock.code from stock;
select stock.code from testdb.stock;
#########################################
select code from stock order by code;
select code, time, close, volume from stock order by code, close;
select code, time, close, volume from stock order by code, close DESC;
select code, time, close, volume from stock order by code DESC, close;
select code, time, close, volume from stock order by code DESC, close DESC;
select code, time, close, volume from stock order by code DESC, close DESC limit 1;
select code, time, close, volume from stock order by close DESC limit 1;
##########################################
select * from stock where time='2021-01-13';
select * from stock where code='600009.XSHG';
select * from stock where close>500;
select * from stock where close between 300 and 400;
select * from stock where close is NULL;
##########################################
select * from stock where close>500 and time='2021-01-13';
select * from stock where close>500 or close<1.5;
select * from stock where ( close>500 or close<1 ) and time='2021-01-13' order by close DESC;
select * from stock where code in ('600009.XSHG', '600519.XSHG');
select * from stock where code in ('600009.XSHG', '600519.XSHG') and time='2021-01-13' order by close;
select * from stock where code in ('600009.XSHG', '600519.XSHG') and not time='2021-01-13';
###########################################
select * from stock where code like '688%' and time='2021-01-13';
select * from stock where code like '%221%' and time='2021-01-13';
select * from stock where code like '6%G' and time='2021-01-13';
select * from stock where code like '603___.XSHG' and time='2021-01-13';
############################################




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值