zoukankan      html  css  js  c++  java
  • [IT学习]sql 入门及实例

    sql 是一种数据库查询语言,可以让你很快的查询到数据。其实一般情况下,你也可以采用excel来查询数据库数据。

    但是人们通常认为sql会更加灵活和方便一些。

    sql学习的入门网站:

    http://www.w3schools.com/SQl/sql_orderby.asp

    https://en.wikipedia.org/wiki/SQL

    sql 学习笔记:

    1、如果你对结构化数据库有概念,那么还是很容易理解的。如果你对结构化数据库一点没有概念,请自行百度结构化数据库,对数据库结构、表、字段、查询(筛选)、增删改、排序数据表等操作有个基本了解。

    2、从Customers 表中查询Country字段内容以U开头的记录。

    SELECT * FROM Customers
    WHERE Country like "U%";

    3、从Customers 表中查询Country字段为USA,并且City字段内容为Seattle或者以P开头的记录。

    SELECT * FROM Customers
    where Country ="USA" and (City ="Seattle" or city like "P%");

    4、从Customers 表中查询City字段内容不重复的记录内容,仅仅返回City字段。(Distinct用来返回字段唯一不重复值的命令)

    SELECT DISTINCT City FROM Customers; 

    5、Like 语句,S%,%S,%Sand%,分别表示S开头,S结尾,包含Sand

    SELECT * FROM Customers
    WHERE Country LIKE '%land%';

    6、fuction 实例:

    SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
    INNER JOIN Employees
    ON Orders.EmployeeID=Employees.EmployeeID)
    GROUP BY LastName
    HAVING COUNT(Orders.OrderID) > 10;

    SELECT ProductName, Price FROM Products
    WHERE Price>(SELECT AVG(Price) FROM Products);

    7、Join的四种

    SQL INNER JOIN

    SQL LEFT JOIN

    SQL RIGHT JOIN

    SQL FULL OUTER JOIN

    8、Union与Join的区别

    The UNION operator is used to combine the result-set of two or more SELECT statements.

    Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

    SQL JOIN

    An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.

    The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN return all rows from multiple tables where the join condition is met.

  • 相关阅读:
    Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动
    dubbox注解的一个坑
    内嵌Tomcat的Connector对象的静态代码块
    Spring Boot启动过程(三)
    Spring Boot启动过程(二)
    Spring Boot启动过程(一)
    SpringMVC基础学习(二)—开发Handler
    JS弹出框
    Oracle的基本学习(三)—函数
    Oracle的基本学习(二)—基本查询
  • 原文地址:https://www.cnblogs.com/viphhs/p/4976454.html
Copyright © 2011-2022 走看看