代码改变世界

随笔分类 -  SQL

MySQL 根据年、季度、月、周、日统计数据

2017-08-17 11:39 by 甘雨路, 640 阅读, 收藏,
摘要: -- 计算每年订单的总价格 select date_format(t.order_time,'%Y') years,sum(t.order_amount) '总价格' from lf_order t group by years; -- 计算每季度订单的总价格 select quarter(t.order_time) '季度',sum(t.order_amount) '总价格' from lf... 阅读全文

数据库 权限表 面试题

2017-07-20 16:48 by 甘雨路, 391 阅读, 收藏,
摘要: MySQL的写法: 第一种写法: select u.name,group_concat(r.name separator ',') rolesnamefrom user u left join user_role ur on u.id = ur.user_idleft join role r on 阅读全文

ORACLE 定时执行存储过程

2017-03-25 10:56 by 甘雨路, 279 阅读, 收藏,
摘要: -- 创建 create table test_lf( test_id varchar(40) primary key, test_name varchar(50) not null, reate_time date ); select t.*,t.rowid from test_lf t; --select t.*,t.rowid from lf_... 阅读全文

Oracle 复制表

2017-02-06 17:21 by 甘雨路, 200 阅读, 收藏,
摘要: -- 复制表 create table newtable as select * from t_stu; select * from newtable; -- 复制表结构,但不复制数据 create table newt as select * from t_stu where 1=2; select * from newt; 阅读全文

oracle 创建表 外键约束

2017-02-05 17:07 by 甘雨路, 740 阅读, 收藏,
摘要: create table usertable( id int primary key, username varchar(32) not null, birthday date, sex char(1), address varchar(256) ); create table orders( ... 阅读全文

oracle 通过序列实现某字段自增

2017-02-05 16:26 by 甘雨路, 1112 阅读, 收藏,
摘要: -- 创建表 create table items( id int primary key, name varchar(32) not null, price int not null, detail varchar(100), pic varchar(512), createtime date ... 阅读全文

Oracle 触发器的简单命令

2016-12-15 16:40 by 甘雨路, 1232 阅读, 收藏,
摘要: -- 创建触发器的基本命令 create or replace trigger td after delete on ss begin dbms_output.put_line('删除成功'); end; -- 创建触发器的基本命令 create or replace trigger dd after insert on ss for each row --没有变量可去掉声明 --decl... 阅读全文

Oracle 小案例

2016-12-15 08:36 by 甘雨路, 237 阅读, 收藏,
摘要: create database cstd; use cstd; /*1:建立学生表*/ create table student ( 学号 char(3) primary key, 姓名 char(8), 性别 char(4), 年龄 int, 班级 char(5) ); insert into student values('108','曾华','男',19,'9... 阅读全文

PL/SQL 存储函数和过程

2016-12-12 17:11 by 甘雨路, 348 阅读, 收藏,
摘要: --存储过程 1.不带参: create or replace procedure 存储过程名 as|is --说明部分 begin --执行的语句; end; 调用存储过程 1 execute 存储过程名 --exec 存储过程名 2 在另外的plsql语句中直接调用 begin 存储过程名; 存储过程名; 存储过程名; end; crea... 阅读全文

PLSQL 申明和游标

2016-12-09 17:20 by 甘雨路, 446 阅读, 收藏,
摘要: --从键盘输入一个数 accept b prompt '请输入一个大于零的数字'; declare anum number := &b; begin while anum>0 loop dbms_output.put_line(anum); anum:=anum-1; end loop; end; declare v_num numb... 阅读全文

PLSQL 的简单命令之五

2016-12-02 17:25 by 甘雨路, 749 阅读, 收藏,
摘要: --1. 查询和Zlotkey相同部门的员工姓名和雇用日期 select a.last_name,a.hire_date ,b.department_name from employees a,departments b where b.department_name in (select department_name from departments, employees where... 阅读全文

PLSQL 的简单命令之四

2016-12-01 11:32 by 甘雨路, 318 阅读, 收藏,
摘要: -- 子查询 -- in 等于表中的任意一个 select * from Stu where id in (select id from scores) -- 和子查询返回结果中的某一个值比较成立即可 select * from scores where id > all (select id from stu ) -- 和子查询返回结果中的所有值比较 select * from sco... 阅读全文

PLSQL 的简单命令之三

2016-11-30 16:21 by 甘雨路, 1314 阅读, 收藏,
摘要: -- 查找两个表中ID相等的 select a.id, a.name,b.math from stu a,scores b where a.id = b.id -- 右外连接 select b.id, a.name,b.math from stu a,scores b where a.id(+) = b.id select b.id, a.name,b.math from stu a r... 阅读全文

PLSQL 的简单命令之二

2016-11-29 18:44 by 甘雨路, 882 阅读, 收藏,
摘要: --1. 查询工资大于12000的员工姓名和工资 select first_name,last_name,salary from employees where salary > 12000 --2. 查询员工号为176的员工的姓名和部门号 select first_name,last_name,department_id from employees where job_id = '... 阅读全文

SQL 的简单命令(增删改查)

2016-11-28 11:14 by 甘雨路, 911 阅读, 收藏,
摘要: -- 查找两个表中ID相等的select a.id, a.name,b.math from stu a,scores b where a.id = b.id -- 右外连接select b.id, a.name,b.math from stu a,scores b where a.id(+) = b 阅读全文