Home Database Mysql Tutorial sql server投影查询、选择查询

sql server投影查询、选择查询

Jun 07, 2016 pm 04:19 PM
server projection Inquire choose

--简单查询 --投影查询 /* 简单查询关键字说明: all :指定显示所有的记录,包括重复行。all是默认设置。 distinct :指定显示所有的记录,但不包括重复行。 top n [percent]:指定从结果中返回前n行,或者前n%的数据记录 * : 表示所有记录 */ --选择一个表

   --简单查询

  --投影查询

  /*

  简单查询关键字说明:

  all :指定显示所有的记录,包括重复行。all是默认设置。

  distinct :指定显示所有的记录,但不包括重复行。

  top n [percent]:指定从结果中返回前n行,或者前n%的数据记录

  * : 表示所有记录

  */

  --选择一个表中指定的列

  --查询学生表中“姓名”,“年龄”

  select Sname , Sage from Student

  --查询学生表中的所有记录

  select * from Student --用*表示所有的列

  --查询学生表中所有学生的姓名,,去掉重复行

  select distinct Sname from Student

  /*

  用distinct关键字可以过滤掉查询结果中重复行

  */

  --查询学生表中前三行的记录

  select top 3 * from Student

  /*

  用top n 可以指定查询表中的前n行记录

  */

  --查询学生表中前50%的记录

  select top 50 percent * from Student

  /*

  用top n percent可以指定查询表中前n%的记录

  */

  --修改查询结果中的列标题

  /*

  修改查询列名的常用方法

  方法一:在列表达式后面直接给出列名

  方法二:用as关键字来连接列表达式和指定的列名

  */

  --将查询结果中的Sname给成“姓名”,Sno改成“学号”,Sage改成“年龄”

  --方法一:

  select Sno 学号,Sname 姓名,Sage 年龄 from Student

  --方法二:

  select Sno as 学号,Sname as 姓名,Sage as 年龄 from Student

  --计算列值

  select 100-Sage as 寿命 from Student

  --选择查询

  /*

  选择查询语法:

  select select_list from table_list

  where search_condition

  //其中有多种语句可以做为条件表达式

  分别是“关系表达式”、“逻辑表达式”、“between语句”、“in语句”、“like语句”、“is [not] null语句”、“复合语句”

  */

  --使用“关系表达式”做为查询条件。。。。。。

  select * from SC

  --查询所有成绩大于等于90分的记录

  select * from SC Student where Grade>=90

  --使用“逻辑表达式”做为查询条件。。。。。。

  /*

  SQL 中的逻辑表达式:

  not :非

  and :与

  or :或

  */

  select * from Student

  --在学生表中查询年龄是19岁的男学生

  select * from Student where Sage = 19 and Ssex = '男'

  --在学生表中查询年龄是19或20岁的学生

  select * from Student where Sage = 19 or Sage = 20

  --在学生表中查询年龄不是19岁的学生

  select * from Student where not Sage = 19

  --使用between关键之做为查询条件。。。。。。。

  /*

  between 语法:

  表达式 [not] between 表达式1 and 表达式2

  使用between关键字可以方便的控制查询结果数据的范围

  注意使用between形成搜索范围是一个“闭区间”

  */

  --查询所有年龄"大于等于"18岁且"小于等于"20岁的学生

  select * from Student where Sage between 18 and 20

  --查询所有年龄不在18到19岁之间的学生

  select * from Student where Sage not between 18 and 19

  --使用in(属于)关键字做为条件表达式......。。。。。

  /*

  同between关键字一样,in关键字的引入也是为了更加方便的限制检索数据的范围

  */

  /*

  in关键字的语法如下:

  表达式 [not] in (表达式1,表达式2,...)

  */

  select * from Student

  --查询所有年龄为18和19岁的学生

  select * from Student where Sage in (18,19)

  --使用like关键字语句做为条件语句。。。。。。

  /*

  like 关键字搜索与指定模式匹配的字符串

  */

  /*

  通配符介绍:

  % :包括零个或多个字符的任意字符串

  _ : 任何单个字符

  []: 代表指定范围内的单个字符,[]中可以是单个字符(如[acef]),也可以是字符范围(如[a-f])

  [^]: 表示不在指定范围内的单个字符,[^]中可以是单个字符(如[^abef]),也可以是字符范围[^a-f]

  */

  /*

  通配符的示例

  like 'AB%' 返回以AB开始的任意字符串

  like 'Ab%' 返回Ab开始的任意字符串

  like '%abc'返回以abc结尾的任意字符串

  like '%abc%'返回包含abc的任意字符串

  like '_ab'返回以ab结尾的任意三个字符的字符串

  like '[ACK]%'返回以A、C或K开始的任意字符串

  like '[A-T]ing' 返回四个字符的字符串,以ing结尾,其首字母的范围是A到T

  like 'M[^c]%' 返回以M开始且第二个字符不是c的任意长度的字符串

  */

  select * from Student

  --查询所有姓王的学生

  select * from Student where Sname like '王%'

  insert into Student(Sno,Sname,Sage,Ssex,Sdept)

  values ('008','张四',20,'男','sc')

  --查询所有名字中带四字的学生

  select * from Student where Sname like '%四%'

  //

  --使用isnull(是否为空)查询。。。。。。

  /*

  说明:在where语句中不能使用比较运算符来进行控制判断,只能使用空值表达式来判断某个表达式是否为空值

  语法如下:

  表达式 is null

  或

  表达式 is not null

  */

  --查询所有学生姓名为空的学生。。。。。。。。。

  select * from Student where Sname is not null

  --使用复合条件查询。。。。。。。。。。。。。。

  /*

  使用复合语句的时候需要使用逻辑运算符把多个条件语句合并

  and

  or

  not

  每个单独的条件语句可以使用()小括号括起来

  */

  //聚合函数(求记录数据的处理结果)

  --聚合函数 (求记录数据的处理结果)

  /*

  聚合函数是在SQL Server 中已经定义好了的一些列函数

  注意:这些函数处理的是一个数据集合,而不是一行单独的记录

  */

  /*

  sum()返回一个数字列或计算列的总和

  avg()返回一盒数字列或计算列的平均值

  min()返回最小值

  max()返回最大值

  count() 返回一个数据列中数据项数

  count(*) 返回找到的行数

  */

  select * from SC

  --求SC表中成绩的平均值

  select AVG(Grade ) as 成绩平均值 from SC

  --求SC表中成绩的总和

  select sum(Grade ) as 成绩平均值 from SC

  --求SC表中的项数

  select count(Grade ) as 记录条数 from SC

  select COUNT(*) as 记录条数 from SC

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can wallpaper engine be shared among families? Can wallpaper engine be shared among families? Mar 18, 2024 pm 07:28 PM

Does Wallpaper support family sharing? Unfortunately, it cannot be supported. Still, we have solutions. For example, you can purchase with a small account or download the software and wallpapers from a large account first, and then change to the small account. Simply launching the software is perfectly fine. Can wallpaperengine be family shared? Answer: Wallpaper does not currently support the family sharing function. 1. It is understood that WallpaperEngine does not seem to be suitable for family sharing environments. 2. In order to solve this problem, it is recommended that you consider purchasing a new account; 3. Or download the required software and wallpapers in the main account first, and then switch to other accounts. 4. Just open the software with a light click and it will be fine. 5. You can view the properties on the above web page"

How to set lock screen wallpaper on wallpaper engine? How to use wallpaper engine How to set lock screen wallpaper on wallpaper engine? How to use wallpaper engine Mar 13, 2024 pm 08:07 PM

WallpaperEngine is a software commonly used to set desktop wallpapers. Users can search for their favorite pictures in WallpaperEngine to generate desktop wallpapers. It also supports adding pictures from the computer to WallpaperEngine to set them as computer wallpapers. Let’s take a look at how wallpaperengine sets the lock screen wallpaper. Wallpaperengine setting lock screen wallpaper tutorial 1. First enter the software, then select installed, and click "Configure Wallpaper Options". 2. After selecting the wallpaper in separate settings, you need to click OK on the lower right. 3. Then click on the settings and preview above. 4. Next

Is there any virus when watching wallpaper engine movies? Is there any virus when watching wallpaper engine movies? Mar 18, 2024 pm 07:28 PM

Users can download various wallpapers when using WallpaperEngine, and can also use dynamic wallpapers. Many users do not know whether there are viruses when watching videos on WallpaperEngine, but video files cannot be used as viruses. Is there any virus when watching movies on wallpaperengine? Answer: No. 1. Just video files cannot be used as viruses. 2. Just make sure to download videos from trusted sources and maintain computer security measures to avoid the risk of virus infection. 3. Application wallpapers are in apk format, and apk may carry Trojan viruses. 4. WallpaperEngine itself does not have viruses, but some application wallpapers in the creative workshop may have viruses.

12306 How to check historical ticket purchase records How to check historical ticket purchase records 12306 How to check historical ticket purchase records How to check historical ticket purchase records Mar 28, 2024 pm 03:11 PM

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

In which folder are the wallpapers of wallpaper engine located? In which folder are the wallpapers of wallpaper engine located? Mar 19, 2024 am 08:16 AM

When using wallpaper, users can download various wallpapers they like for use. Many users do not know which folder the wallpapers are in. The wallpapers downloaded by users are stored in the content folder. Which folder is the wallpaper in? Answer: content folder. 1. Open File Explorer. 2. Click "This PC" on the left. 3. Find the "STEAM" folder. 4. Select "steamapps". 5. Click “workshop”. 6. Find the “content” folder.

How to check your academic qualifications on Xuexin.com How to check your academic qualifications on Xuexin.com Mar 28, 2024 pm 04:31 PM

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];

Does wallpaper engine consume a lot of power? Does wallpaper engine consume a lot of power? Mar 18, 2024 pm 08:30 PM

Users can change their computer wallpapers when using WallpaperEngine. Many users don't know that WallpaperEngine consumes a lot of power. Dynamic wallpapers consume a little more power than static wallpapers, but not a lot. Does wallpaperengine consume a lot of power? Answer: Not much. 1. Dynamic wallpapers consume a little more power than static wallpapers, but not a lot. 2. Turning on dynamic wallpaper will increase the computer's power consumption and take away a small amount of memory usage. 3. Users do not need to worry about the serious power consumption of dynamic wallpapers.

Where is the wallpaper engine subscription record? Where is the wallpaper engine subscription record? Mar 18, 2024 pm 05:37 PM

How to check wallpaper subscription records? Many users have made a large number of subscriptions on this software, but may not know how to query these records. In fact, you only need to operate it in the browsing function area of ​​the software. Where are wallpaperengine subscription records? Answer: In the browsing interface. 1. Please start the computer first and enter the wallpaper software. 2. Find the Browse tab icon in the upper left corner of the application and click it. 3. In the "Browse" interface, you will see an overview of various wallpapers and feeds. 4. Enter the keywords you want to search in the search box in the upper right corner. 5. Relying on the search results, you can find the source information of the wallpaper subscription. 6. Click on the corresponding feed to enter its web page. 7. Ordering

See all articles