• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LilyLiya
博客园    首页    新随笔    联系   管理    订阅  订阅
SQL学习笔记-day1

 

  • What is SQL?

           SQL stands for Structured Query Language. A sequel is a set of commands. SQL is a set of commands that can be sent to the database, then the database is going to interpret those commands and excute them and perform tasks.

  •  SQL is not case sensitive(大小写不敏感)
  •  Retrieving Data Using the SELECT Clause   

         SELECT * FROM emp /* star is to query everything in that table*/

         SELECT job, ename FROM emp /* comma is to query multiple columns */ 

         notes: 

  1. need to specify a single command at a time,每次选中并运行一个命令。
  2. a command that ends with the semi-colon statement
  3. separates one statement from another is the semi-colon. 分号隔开不同的命令
  4. you can have multiple statements, but run one statement at a time。
  5. can make the statement multiple lines, which is more readable
  • get the unique values in one column of a table

         select distinct job from emp;

  • WHERE, return the specific info where some cases satisfied.

        SELECT* FROM EMP WHERE job = 'MANAGER'

        /*if 'maneger', no data found,这里“=”后面的值需要注意大小写*

  • AND

        SELECT * FROM emp

        WHERE job = 'MANAGER'

        AND sal = 2850

        AND ename = 'BLAKE'

        AND empno = 7698

  • Operations

         =, !=, <=, >=, <, >

         SELECT * FROM EMP

         WHERE JOB != 'MANAGER'

         AND COMM > SAL

  • OR

         SELECT * FROM EMP
         WHERE JOB = 'CLERK'
         OR JOB = 'SALESMAN

  • IN / NOT IN == OR

         SELECT ENAME, HIREDATE

         FROM EMP

         WHERE DEPTNO = 20

         OR DEPTNO = 30

 

         SELECT ENAME, HIREDATE

         FROM EMP

         WHERE DEPTNO IN (20, 30)

  • BETWEEN... AND...(boundary inclusive) NOT BETWEEN... AND...(boundary not inclusive)

         SELECT * FROM EMP

         WHERE HIREDATE BETWEEN '04/02/1981' AND '01/12/1983'

  • IS NULL (is not null), no data, which is different from 0 value.

        SELECT * FROM EMP

        WHERE COMM is null

posted on 2021-01-02 14:01  LilyLiya  阅读(76)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3