使用连接SQL 1999SELECT table1.column, table2.columnFROM table1[NATURAL JOIN table2] |[JOIN table2 USING (column_name)] |[JOIN table2 ON (table1.column_name = table2.column_name)]|[LEFT|RIGHT|FULL OUTER JOIN table2 ON (table1.column_name = table2.column_n…
这个月碰到几个人问我关于"SQL SERVER中INNER JOIN 与 IN两种写法的性能孰优孰劣?"这个问题.其实这个概括起来就是SQL Server中INNER JOIN与子查询孰优孰劣(IN是子查询的实现方式之一,本篇还是只对比INNER JOIN与子查询IN的性能,如果展开INNER JOIN与子查询性能对比,范围太大了,没法一一详述).下面这篇文章,我们就INNER JOIN与子查询IN这两种写法孰优孰劣,在不同场景下进行一下测试对比一下,希望能解答你心中的疑惑. 下面例子…
背景 在一次面试的时候,面试官让我说一下这三者的使用场景和区别,当时瞬间懵逼,哈哈.回来赶快看一看,记下来. 详解 inner join 等值查询:返回两张表中,联结字段值相等的组合记录 举例:所有学生参加考试,学生考试结果查询 表如下 表Student(学生表)记录如下: t_id name 1 龙 2 情 3 风 4 月 5 度 表Score(分数表)记录如下: c_id num t_id 1 50 1 2 88 2 3 90 3 4 62 4 5 0 5 查询语句:select s.t_i…
使用INSERT语句INSERT INTO table [(column [, column...])]VALUES (value [, value...]); INSERT INTO departments(department_id, department_name, manager_id, location_id)VALUES (70, 'Public Relations', 100, 1700);字符和日期需要用单引号 INSERT INTO employeesVALUES (114,…
重建scott用户@?/rdbms/admin/utlsampl.sql@--执行?--$ORACLE_HOME 字符区分大小写:SELECT last_name, job_id, department_idFROM employeesWHERE last_name = 'Whalen' ; 使用字符函数:SELECT last_name, job_id, department_idFROM employeesWHERE upper(last_name) = 'WHALEN' ; SELECT…
第一节课: 启动数据库并且使用特定用户连接:su - oracle; 启动sqlplus并且使用sys连接:conn / as sysdba; 启动数据库:startup; 解锁用户:alter user hr identified by hr;alter user hr account unlock; 使用hr连接:conn hr/hr;select * from tab;desc employees;select * from departments; 开发工具:plsql develope…
大小写转换函数LOWER('SQL Course') = sql courseUPPER('SQL Course') = SQL COURSEINITCAP('SQL Course') = Sql CourseSELECT employee_id, last_name, department_idFROM employeesWHERE last_name = 'higgins'; SELECT employee_id, last_name, department_idFROM employees…
隐式转换select * from emp where empno='7788'字符(char,varchar2)转换为数字(number)或日期(date)数字或日期转换为字符 显式转换字符转换为数字或日期(TO_NUMBER, TO_DATE)数字或日期转换为字符(TO_CHAR) TO_CHAR(date, 'format_model')select sysdate, to_char(sysdate,'yyyy') yyyy, to_char(sysdate,'year') year,fr…
schema(模式)一个用户下一组对象的集合,一般与用户名一致. 视图 CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view [(alias[, alias]...)] AS subquery [WITH CHECK OPTION [CONSTRAINT constraint]] [WITH READ ONLY [CONSTRAINT constraint]]; ; desc empvu80; grant create view to scott; crea…
组函数AVGCOUNTMAXMINSUMVARIANCE:方差STDDEV:标准差 SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary)FROM employees WHERE job_id LIKE '%REP%'; SELECT MIN(hire_date), MAX(hire_date) FROM employees; COUNT(expr) 返回expr为非空值的行数:SELECT COUNT(commission_pct) …