有关数据库的增删查改sql编写(已我最近做的武汉车都管理系统项目为例)

数据库的增删查改sql

标题1. 数据库的介绍

部门dept的数据库:
在这里插入图片描述
产品车的品牌brand的数据库:
在这里插入图片描述
员工staff的数据库:(deptid是外键来自dept)
在这里插入图片描述
客户customer的数据库:(staffid是外键来自staff)
在这里插入图片描述
产品production的数据库:(brandid是外键来自brand)
在这里插入图片描述
订单order的数据库:(有很多外键)
在这里插入图片描述

2.有关数据库的一些操作的sql编写

  2.1  单表查询

(1)查询dept的全部信息

 select  * from dept ;

(2)通过dept的编号deptid=1查询编号为一的部门信息

select * from dept where dept.deptid = 1;

(3)查询以“王”开头,且倒数第3个字符为“航”的员工的详细情况

select * from staff where staff.sname like '王%航_';

(4)查询名字中有倩的女员工(模糊查询中任意位置上有倩)

 select * from staff  where staff.sname like '%倩%' and staff.ssex = '女';

(5)分页中:查询staff数据库中一共有多少条数据。

select count(*) from staff;

(6)查询汽车中超过所有汽车商品的平均售价的各个商品号和售价

select  p1.productid,p1.pout  from production p1 
where  p1.pout>(
select  AVG(p2.pout) from production p2
) ;

猜你喜欢

转载自blog.csdn.net/qq_43479839/article/details/104714146