• [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] SpEL
    [spring学习2] 装配
    [spring] proxyMode
    [spring] @PropertySource
    [一些问题] 在vscode中添加jar库
    [spring] ApplicationContext相关问题
    gradle 打包
    [spring学习1] IoC容器
    spring快速开始
    准备要写的笔记备忘录
  • 原文地址:https://www.cnblogs.com/viphhs/p/4976454.html
Copyright © 2020-2023  润新知