2024-11-01

lombok

create database shop;NBSP //创建一个名为shop的数据库

use shop;NBSP //使用shop库

//建一张名为Product的表

//包含一个id字段,字段类型为int(整数)not null表示不允许为null, promary key表示该字段为主键,auto_increment表水

create table Product(id int not null primary key auto_increment);

//添加表结构语句 添加一个名为name的 类型为verchr(字符串,长度为100)的属性到product表中

alter table Product add column name varchar(100);

//删除表结构语句

alter table Product drop column name;

//查看product的表结构

desc Product;

//添加一条数据小括号里写我要添加那些字段,values后按照顺序写值

insert into Product (name,project,type) values("帽子"99"服饰");

//查询Product表中全部的数据

select * from Product;

//副除Product表中id为1的数据

//分组查询,统计有多少条

select type,count(*) from Product group by type;

//打八折,AS改名字

select name,price,price * 0.8 AS price2 from Product;

//大于300打八折

select name,price,price * 0.8 AS price2 from Product where price > 300;

//大于380打八折

select name,price,price * 0.8 AS price2 from Product where price <= 380 and type='衣服';

//求和

select sum(price) from Product;

//平均值

select avg(price) from Product;

//最大值

select max(price) from Product;

//最大值最小值

select max(price), min(price) from Product;

//删除Product表中id为1的数据

delet from Product where id=1;

//修改Product表中id为2的记录的name值为拖鞋

update Product set name="拖鞋"where id=2;

//条件查询

select * from Product where type="服饰";

//多个条件查询

select * from Product where type="服饰" and price >=100;

//只查询name,price

select name,price from Product;

//分组查询

select type from Product group by type;

//去重查询

select distinct type from Product;

//分组查询,统计有多少条

select type,count(*) from Product group by type;


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • create database shop;NBSP //创建一个名为shop的数据库 use shop;NBSP ...
    帅哥_6f43阅读 53评论 0 0
  • show databases; //查看数据库列表 create database shop; //创建一个名...
    sunshine329阅读 49评论 0 0
  • show databases; //查看数据库列表 create database shop; //创建一个名...
    龙虎蟒阅读 50评论 0 0
  • show databases; //查看数据库列表 create database shop; //创建一个名...
    纠结呐阅读 67评论 0 0
  • Mysql基本语法 基本命令 SHOW databases; -- 查看数据仓库USE shop;-- 使用仓库S...
    刘甜甜a阅读 48评论 0 0