To generate a dataset with subtotal totals using SQL statements:
Test User: Scott
Test table: Dept,emp
//////////////////////////////////
Retrieve a dataset that needs to be counted
Select Dept.dname,emp.job,sal from Emp,dept
where Emp.deptno=dept.deptno;
//////////////////////////////////
Summary according to department name and position, and for each department
Generate ' subtotal ', and finally generate ' totals '.
Select
Decode (Grouping (dept.dname), 1, ' total: ', dept.dname) dn
to Ward's salary in the EMP data table. The above query process is equivalent to two steps in the execution process.
(1) Execute "Select Sal from scott.emp where ename= ' WARD '", Draw sal=1250;
(2) Execute "Select Emp.empno,emp.ename,emp.job,emp.sal from Scott.emp where sal>=1250;"
4.4.2 nested query with "in"
In the command edit area, execute the following statement.
―――――――――――――――――――――――――――――――――――――
Privileges3) Connect to the DBA account and authorize:Sql> Connect Sys/[email protected]Connected.Sql> Grant GLOBAL QUERY REWRITE to Scott;Grant succeeded.Sql> Grant CREATE any INDEX to Scott;Grant succeeded.4) When connecting to the Scott account, create a function-based index:Sql> Connect Scott/[email protected]Connected.Sql> CREATE INDEX Sal_comm on EMP ((Sal+comm) *12, Sal,comm)2 Tablespace users Storage (initial 64k next 64k pctincrease 0);Index created.1) Use the function index in the que
Sal ASC;Example: sorting in descending orderSELECT * from emp ORDER by Sal DESC;Example: require all employee information to be queried, sorted by salary from highest to lowest, and if the wage is the same, the date of employment is sorted from early to lateThere must be two fields sorted at this time: salary (DESC), employment Date (ASC);SELECT * from emp ORDER by Sal DESC, HireDate ASC;Sql> SELECT * from emp ORDER by Sal DESC, HireDate ASC;EMPNO ename JOB MGR hiredate SAL COMM DEPTNO---------
Tags: Oracle overIn order to facilitate learning and testing, all examples are created under the Oracle's own user Scott.CREATE TABLE EMP ( empno number (4) Not null, ename NBSP;VARCHAR2 (Ten), job NB Sp NBSP;VARCHAR2 (9), Mgr number (4), hiredate date, sal number ( 7,2), Comm Number (7,2), deptno Number (2)) ALTER TABLE emp add constraint pk_emp Prim ary Key (EMPNO); insert into EMP (EMPNO, ename, Job, Mgr, HireDate, Sal, Comm, Deptno) valu ES (7369, ' SMITH ', ' clerk ', 7902, to_
/schema/view/viewWorking with Object Types Database_export/schema/table/constraint/constraintWorking with Object Types Database_export/schema/table/index/statistics/index_statisticsWorking with Object Types Database_export/schema/table/constraint/ref_constraintWorking with Object Types Database_export/schema/table/statistics/table_statisticsWorking with Object Types Database_export/statistics/markerORA-39082: Object type VIEW: "SCOTT". " V_test "created with compile warningORA-39082: Object type
+comm) *12, Sal,comm)*ERROR at line 1:Ora-01031:insufficient Privileges3) Connect to the DBA account and authorize:Sql> Connect Sys/[email protected]Connected.Sql> Grant GLOBAL QUERY REWRITE to Scott;Grant succeeded.Sql> Grant CREATE any INDEX to Scott;Grant succeeded.4) When connecting to the Scott account, create a function-based index:Sql> Connect Scott/[email protected]Connected.Sql> CREATE INDEX Sal_comm on EMP ((Sal+comm) *12, Sal,comm)2 Tablespace users Storage (initial 64k next 64k pctin
collections.Multiline subquery:If the subquery returns the result of multiple rows, we call it a multiline subquery. Multiline subqueries use different comparison operation symbols, which are in, any, and all. Query employee information for wages below any one "clerk" wage. Execute the following query:Select Empno, ename, job,sal from EMP where Sal Note: 4 of the employees in the EMP table are "clerk" and their salaries are 800, 1100, 950, 1300, respectively. There are 2 records that meet wages
connectorSql> Select Ename | | ' The salary is ' | | Sal from EMP;ename| | ' The salary is ' | | SAL———————————————————-Smith's salary is 800.Allen's salary is 1600.Ward's salary is 1250.Jones's salary is 2975.Martin's salary is 1250.Blake's salary is 2850.Clark's salary is 2450.Scott's salary is 3000.King's salary is 5000.Turner's salary is 1500.Adams's salary is 1100.James's salary is 950.Ford's salary i
from:http://blog.csdn.net/m13666368773/article/details/7007197exists says () a subquery Returns a result that is not NULL. Indicates that the where condition will execute the main SQL statement, and if NULL indicates that the WHERE condition is not true, the SQL statement will not execute. Instead of exists and exists, the subquery result is empty, which means that the where condition is true and the SQL statement is executed. Responsible for not executing.Prior to learning Oracle database, cont
: Close REF CURSOR name; Sql> declare 2 type emp_cursor is REF CURSOR; 3 my_cursor emp_cursor; 4 v_ename emp.ename%type; 5 v_ Sal Emp.sal%type; 6 V_deptno Dept.deptno%type: = p_deptno; 7 V_dname Dept.dname%type; 8 begin 9 Select Dname to V_dname from dept where deptno = V_deptno; Dbms_output.put_line (' Department: ' || V_dname); One open my_cursor for the ename, Sal from emp where deptno = V_deptno; Loop Fetch my_cursor Exit when My_cursor%notfound; Dbms_output.put_line ('--nam
comparisonHere you can see that the id=2 and id=4 columns of the T1 table are deleted by the thread_id=182 user, that is, the Helei user#161208 19:33:39serverid1250end_log_pos5275CRC32 0x2ae798a9querythread_id=182exec_time=
0error_code=0 settimestamp=1481254419/*!*/;
BEGIN/*!*/; #at5275 #161208 19:33:39serverid1250end_log_pos5324 Crc320x2cf42817rows_query #deletefromt1where id=2 #161208 NBSP;19:34:07NBSP;SERVERNBSP;IDNBSP;1250NBSP;NBSP;END_LOG_POSNBSP;5885NBSP;CRC32 0x947106d4querythread_id=182
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.