首页 > 数据库 >sql常用语句

sql常用语句

时间:2023-02-08 14:33:10浏览次数:48  
标签:语句 salary 常用 name employees sql deptno where select

1.创建部门表
create table dept(
deptno int primary key,
dname varchar(9),
loc varchar(10)
)

2.创建员工表
create table employees(
empno int primary key,
name char(10) not null,
deptno int,
manager int,
hiredate date,
salary numeric(7,2)
)

3.创建经理表
create table managers(
empno int primary key,
title
)


4.insert插入
insert into 表名 values( );
向员工表插入记录,包括所有字段的值。
insert into emoloyees values(1,'张三'.......)

插入和修改数据不能违反主键约束

5.select查询
查询员工表所有信息
select * from employees;

查询员工表某一字段的信息
select salary,name from employees

6.distinct去掉重复的值
select distinct manager from employees

7.where用法
select name,salary from employees where deptno=3;

8.and or 运算符
select * from employees where (deptno=3 or deptno) and salary>=5000;

9.like的用法
select * from employees where name like 'li%'

10.in匹配多个值。

11.between指定范围
select name from employees where hiredate between '2013-01-01' and '2013-12-31';

12,order by 排序(降序)
select name,salary from employees order by salary desc;

13.update更新数据
update employees set deptno=2,manager=4 where empno=4;

14.delete 删除数据
delete from employees where empno=9;

15.index索引
create index in_name on employees(name);

16.view视图
create view view_name as select name,salary from employees where hiredate<'2015-01-01'
select * from view_name

更新视图view_name
update view_name


17.null的用法
select * from employees where manager is not null.

18.别名。
select name 姓名,salary 工资 from emploees e;


19.join连接。内连接inner join 左连接left join 右连接

 

标签:语句,salary,常用,name,employees,sql,deptno,where,select
From: https://www.cnblogs.com/suquanxing/p/17101641.html

相关文章

  • .NET Core SshClient + Npgsql 实现ssh隧道访问内网数据库
    privateconststringSSH_USER="root";//ssh账号privateconststringSSH_PASSWORD=".";//ssh密码,若使用密钥且没密码时填......
  • 【常用排序】快速排序与归并排序
    ❤️前言本文介绍两种基于分治思想的经典排序算法:归并排序与快速排序......
  • 使用 NineData 高效编写 SQL
    SQL是StructuredQueryLanguage的缩写,中文翻译为“结构化查询语言”。它是关系型数据库的标准语言,所有的关系型数据库管理系统(RDBMS),比如MySQL、Oracle、SQLServer、Po......
  • 云时代,最好用的MySQL客户端工具推荐
    数据库图形客户端(GUI)工具,可以大大帮助开发者提升SQL编写与开发的效率。在云时代,企业越来越多的开始采用RDS,同时也还有部分本地IDC自建数据库,而在云端也会选择/尝试多个不同......
  • 【MySQL高级】索引优化
    目录​​1.使用索引优化​​​​1.1数据准备​​​​1.2避免索引失效应用-全值匹配​​​​1.3避免索引失效应用-最左前缀法则​​​​1.4避免索引失效应用-其他匹配原则​......
  • sqlserver 新建的表 提示表对象名不存在
    问题描述:记录一下以前的遇到的一个小问题。SQL中表确实存在,  但是却显示对象名无效,如下图所示:  办法:使用Ctrl+shift+R 刷新下SQLServerManagementStudi......
  • navicat for mysql
    1、先下载并安装navicat_premium_trial_64(注意是64bit版本) 链接:https://pan.baidu.com/s/11nRYrmddDLj1R0rrIfbKcg提取码:5cmv2、下载PatchNavicat并将其复制到Na......
  • MySQL 如何实现数据更新
    一般在更新时会遇到以下场景:1.所有字段全部更新;2.根据条件更新字段中的某部分内容;3.根据不同的条件更新不同的值,以下是几种场景中常用的update方法。一、方法分类二、具......
  • EFCore 封装Repository(可扩展不同数据的sql操作)
    参照:https://www.cnblogs.com/youhui/articles/10813468.html接口类:publicinterfaceIRepository<TEntity,TKey>whereTEntity:class{#region查找......
  • 解决com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too
    1.今天遇到一个蛮奇怪的问题,项目一天都没啥问题,然后等我下班测试就跟我说报错报错如下:    2.然后我立马去控制台打印实时日志查看报如下错;    3.经......