second day

Learn how to write (build) simple SQL query statements in SQL Server 2005 using the SELECT statement. 

1

Displaying or Selecting Columns from a Table

Using a SELECT statement, we do not have to display or return all the columns from a table.

SELECT Name --呈现表中名字一列的值
FROM   Dependent
SELECT * --呈现所有的列项数据
FROM   Dependent
2
ORDER BY
we can use the OROER BY clause in  the SELECT satement to display the contents
of a table in a predictate manner.
for example
SELECT dname, age
FROM   Dependent
ORDER  BY age  --以年龄的大小来呈现所输出的数据
If the field that you choose to ORDER BY contains nulls, the fields that 
have null values assigned to them are placed at ((the top of)) the displayed 
list of output. This is because of the way SQL Server stores null values internally. Look at the output of the following query
2.1
Ordering Within an Order
There will be times when you will want to sort groups within 
an order by another order. SQL Server syntax allows you to do this.
For example, using the Dependent table, if you want to order all 
the dependents by sex, and within sex you want to order by age in 
descending order, would you type the following query:
for example
SELECT dname, sex, age
FROM   Dependent
ORDER  BY sex, age DESC
if you want to order by descending order of sex, and descending order of age
as follows;
SELECT dname, sex, age
FROM   Dependent
ORDER  BY sex DESC, age DESC
 
3
WHERE
The WHERE clause is a row filter that is used to restrict the 
output of rows (or tuples )in a result set. When the WHERE clause 
is used, the SQL Server database engine selects the rows from the 
table for the result set that meet the conditions listed in the 
WHERE clause.
for example
SELECT   dname, age
FROM     Dependent
WHERE    age <= 5
ORDER BY age
at lase or and between operator is simple,don't give some examples.
 
4 COUNT 
The COUNT function is used to return a count of the number of rows 
 
for example
 
SELECT COUNT(*)
FROM   Dependent
 
5 ROWCOUNT
 
limiting the number of rows that can be the returned by a SELECT statement

for example

SET ROWCOUNT 10 --输出前10行数据
SELECT *
FROM   Dependent

After using ROWCOUNT, you should reset the ROWCOUNT property by:

SET ROWCOUNT 0
6 注意2。9节内容

 

 
 
 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值