SQL基础回顾系列一 单表查询(select语句)
SQL基础回顾系列一 单表查询(select语句) 很久没有写博客了,最近一直忙于找工作,心都没办法安静下来。通过最近的面试,也给自己暴露了不少问题,其中很重要的一块就是数据库,因为项目的原因,最近两年在文思的香港马会的项目组都没有使用过数据库,所以数
SQL基础回顾系列一 单表查询(select语句)
很久没有写博客了,最近一直忙于找工作,香港服务器,心都没办法安静下来。通过最近的面试,也给自己暴露了不少问题,其中很重要的一块就是数据库,因为项目的原因,最近两年在文思的香港马会的项目组都没有使用过数据库,所以数据库这一块也成了我的短板,所以也借离职在家这段时间,系统地回顾一下数据库的知识,我会写成一个系列并坚持写下去。
先从select语句写起,因为它是学习T-SQL的基础。首先总结一下select语句逻辑处理顺序,如下,下面按照逻辑顺序来总结。
from
where
group by
having
select
over
distinct
top
order by
from子句from子句是在逻辑处理阶段第一个要处理的查询子句。它是用来指定要查询的表名,香港服务器,以及对表进行操作的表运算符。下面的例子是对Sales数据库架构中的Orders表进行查询,看sql语句:
SELECT orderid,custid,empid,orderdate,freight FROM Sales.Orders;
执行结果:
注意:1> 应该总是用数据库架构来限定代码中的对象名称,如Sales.Order。
2> 应该显示指定要查询的列,避免一些额外的代价。
3> select出的结果看起来是以特定的顺序返回(以orderid的升序排列)的,香港服务器, 但不能保证绝对这样。
4> Sql server分隔标识符使用方括号,如[Order Details]
它的作用是过滤由from阶段返回的行,可以指定一个谓词或逻辑表达式。如where阶段只保留id为71的客户下的订单,sql代码如下:
SELECT orderid,custid,empid,orderdate,freight FROM Sales.Orders WHERE custid=71;
程序输出结果为:
group by阶段可以将前面逻辑查询处理阶段返回的行按“组”进行组合,每个组由在group by子句中指定的各元素决定。如对于where阶段返回的数据中出现的每个雇员id和订单年份值的唯一组合,sql代码如下:
SELECT empid , YEAR(orderdate) AS orderyear , SUM(freight) AS totalfreight , COUNT(*) AS numorders FROM Sales.Orders empid , YEAR(orderdate);
程序输出结果为:
注意:1,group by阶段之后的所有阶段(包括having,select以及order by)的操作对象都是组。比如这里是select。
2,一个元素如果不在group by列表中出现,就只能作为聚合函数(Count,Sum,Avg,Min以及Max)的输入,比如这里的Sum和Count函数。
posted on

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

The Xiaomi Mi 15 series is expected to be officially released in October, and its full series codenames have been exposed in the foreign media MiCode code base. Among them, the flagship Xiaomi Mi 15 Ultra is codenamed "Xuanyuan" (meaning "Xuanyuan"). This name comes from the Yellow Emperor in Chinese mythology, which symbolizes nobility. Xiaomi 15 is codenamed "Dada", while Xiaomi 15Pro is named "Haotian" (meaning "Haotian"). The internal code name of Xiaomi Mi 15S Pro is "dijun", which alludes to Emperor Jun, the creator god of "The Classic of Mountains and Seas". Xiaomi 15Ultra series covers

If you want to check the activation date using an Apple mobile phone, the best way is to check it through the serial number in the mobile phone. You can also check it by visiting Apple's official website, connecting it to a computer, and downloading third-party software to check it. How to check the activation date of Apple mobile phone Answer: Serial number query, Apple official website query, computer query, third-party software query 1. The best way for users is to know the serial number of their mobile phone. You can see the serial number by opening Settings, General, About This Machine. . 2. Using the serial number, you can not only know the activation date of your mobile phone, but also check the mobile phone version, mobile phone origin, mobile phone factory date, etc. 3. Users visit Apple's official website to find technical support, find the service and repair column at the bottom of the page, and check the iPhone activation information there. 4. User

Title: How to use Oracle to query whether a table is locked? In Oracle database, table lock means that when a transaction is performing a write operation on the table, other transactions will be blocked when they want to perform write operations on the table or make structural changes to the table (such as adding columns, deleting rows, etc.). In the actual development process, we often need to query whether the table is locked in order to better troubleshoot and deal with related problems. This article will introduce how to use Oracle statements to query whether a table is locked, and give specific code examples. To check whether the table is locked, we

Since the Huawei Mate60 series went on sale last year, I personally have been using the Mate60Pro as my main phone. In nearly a year, Huawei Mate60Pro has undergone multiple OTA upgrades, and the overall experience has been significantly improved, giving people a feeling of being constantly new. For example, recently, the Huawei Mate60 series has once again received a major upgrade in imaging capabilities. The first is the new AI elimination function, which can intelligently eliminate passers-by and debris and automatically fill in the blank areas; secondly, the color accuracy and telephoto clarity of the main camera have been significantly upgraded. Considering that it is the back-to-school season, Huawei Mate60 series has also launched an autumn promotion: you can enjoy a discount of up to 800 yuan when purchasing the phone, and the starting price is as low as 4,999 yuan. Commonly used and often new products with great value

MySQL and PL/SQL are two different database management systems, representing the characteristics of relational databases and procedural languages respectively. This article will compare the similarities and differences between MySQL and PL/SQL, with specific code examples to illustrate. MySQL is a popular relational database management system that uses Structured Query Language (SQL) to manage and operate databases. PL/SQL is a procedural language unique to Oracle database and is used to write database objects such as stored procedures, triggers and functions. same

How to check the latest price of Tongshen Coin? Token is a digital currency that can be used to purchase in-game items, services, and assets. It is decentralized, meaning it is not controlled by governments or financial institutions. Transactions of Tongshen Coin are conducted on the blockchain, which is a distributed ledger that records the information of all Tongshen Coin transactions. To check the latest price of Token, you can use the following steps: Choose a reliable price check website or app. Some commonly used price query websites include: CoinMarketCap: https://coinmarketcap.com/Coindesk: https://www.coindesk.com/ Binance: https://www.bin
