• 第三章 查询入门


    1.基本描述

        本章讲解SELECT语句的各个组成部分及它们之间是如何相互作用的。

    2.基本样例

    SELECT emp_id, fname, lname FROM employee 
    WHERE lname = 'Bkadfl';
    
    SELECT fname, lname FROM employee;
    
    SELECT * FROM department;
    
    SELECT dept_id, name FROM department;
    
    SELECT name FROM department;
    
    SELECT emp_id, 'ACTIVE', emp_id * 3.14159, UPPER(lname) FROM employee;
    
    SELECT VERSION(), USER(), DATABASE();
    
    SELECT emp_id, 'ACTIVE' status, emp_id * 3.14159 empid_x_pi, UPPER(lname) last_name_upper FROM employee;
    
    SELECT emp_id, 'ACTIVE' AS status, emp_id * 3.14159 AS empid_x_pi, UPPER(lname) AS last_name_upper FROM employee;
    
    SELECT cust_id FROM account;
    
    SELECT DISTINCT cust_id FROM account;
    
    SELECT e.emp_id, e.fname, e.lname FROM (SELECT emp_id, fname, lname, start_date, title FROM employee) e;
    
    CREATE VIEW employee_vw AS 
    SELECT emp_id, fname, lname, YEAR(start_date) start_year FROM employee;
    
    SELECT emp_id, start_year FROM employee_vw;
    
    SELECT employee.emp_id, employee.fname, employee.lname, department.name dept_name 
    FROM employee INNER JOIN department ON employee.dept_id = department.dept_id;
    
    SELECT emp_id, fname, lname, start_date, title FROM employee
    WHERE title = 'Head Teller';
    
    SELECT emp_id, fname, lname, start_date, title
    FROM employee WHERE title = 'Head Teller' AND start_date > '2006-01-01';
    
    SELECT emp_id, fname, lname, start_date, title FROM employee
    WHERE title = 'Head Teller' OR start_date > '2006-01-01';
    
    SELECT emp_id, fname, lname, start_date, title FROM employee
    WHERE (title = 'Head Teller' AND start_date > '2006-01-01') OR (title = 'Teller' AND start_date > '2006-01-01');
    
    SELECT d.name, count(e.emp_id) num_employees
    FROM department d INNER JOIN employee e
    ON d.dept_id = e.dept_id GROUP BY d.name 
    HAVING count(e.emp_id) > 2;
    
    SELECT open_emp_id, product_cd FROM account;
    
    SELECT open_emp_id, product_cd FROM account ORDER BY open_emp_id;
    
    SELECT open_emp_id, product_cd FROM account ORDER BY open_emp_id, product_cd;
    
    SELECT account_id, product_cd, open_date, avail_balance FROM account ORDER BY avail_balance DESC;
    
    SELECT cust_id, cust_type_cd, city, state, fed_id FROM customer ORDER BY RIGHT(fed_id, 3);
    
    SELECT emp_id, title, start_date, fname, lname FROM employee ORDER BY 2, 5;
    
  • 相关阅读:
    4月19日 疯狂猜成语-----第五次站立会议 参会人员:杨霏,袁雪,胡潇丹,郭林林,尹亚男,赵静娜
    prototype
    angularJs scope的简单模拟
    angularjs DI简单模拟
    洗牌算法
    深入探索 TCP TIME-WAIT
    Logitech k480 蓝牙键盘连接 ubuntu 系统
    在 centos6 上安装 LAMP
    vlc 播放器的点播和广播服务
    Linux 文件系统及 ext2 文件系统
  • 原文地址:https://www.cnblogs.com/LuckPsyduck/p/12608190.html
Copyright © 2020-2023  润新知