zoukankan      html  css  js  c++  java
  • 第三章 查询入门

    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;
    
  • 相关阅读:
    [C语言] 交换排序之冒泡排序的特性及实现
    [C语言] 选择排序之鸡尾酒排序的特性及实现
    [C语言] 选择排序之直接选择排序的特性及实现
    计蒜客 蓝桥杯模拟 快速过河
    计蒜客 蓝桥杯模拟 瞬间移动 dp
    计蒜客 蓝桥杯模拟 充话费
    计蒜客 蓝桥杯模拟二 区间合并 打扫教室
    商品类目短文本分类总结
    SpringBoot项目创建及入门基础
    Joyful HDU
  • 原文地址:https://www.cnblogs.com/LuckPsyduck/p/12608190.html
Copyright © 2011-2022 走看看