SQL classic example of notes

Foreword

This article is based on the classic examples of books I read SQL written notes, I think the only record valuable content

Chapter One: retrieve records

Where the use of aliases in the words

--错误实例
select p as PartNumber from Product where PartNumber='LMKHS'

Where the use of aliases in words, the result of an error, the reason is because SQL execution order is

  1. From
  2. Where
  3. Select

Where you can see the first implementation than Select, Select inside so the alias is defined, Where there certainly does not take

Solution

If you want to use the following in Where in, you can use the embedded view

  1. Aggregation function: for example, min (), max (), sum (), avg ()
  2. Scalar query: must and can only return the results of a query select one row
  3. Window function
  4. Alias: this embodiment as
--内嵌视图如下
select * from(
    select p as PartNumber from Product
) temp where PartNumber='LMKHS'

Guess you like

Origin www.cnblogs.com/yunquan/p/12061451.html