SQLServer learning (additional clause of a query) (c)

1) Order By (sort)

A single keyword Sort:

SELECT WorkNo,NAME,DeptName,InDate 
FROM S_A_User 
WHERE InDate IS NOT NULL 
ORDER BY InDate DESC

Data entry staff were sorted by date;

Sort multiple keywords:

SELECT WorkNo,NAME,DeptName,InDate
FROM S_A_User
WHERE InDate IS NOT NULL
ORDER BY DeptName DESC,InDate ASC

Separated by commas, ascending, descending written after the sort field;

 

2) Group By (packet)

It refers to the group by group, and that group is in what field behind the field by then, like statistics a number of men and women students in the class, students will first need to be grouped with gender field, and then counting statistics

SELECT Sex,COUNT(*) FROM S_A_User GROUP BY Sex

The SELECT Sex, COUNT ( * ) the FROM S_A_User the WHERE the DeptName the LIKE  ' % design management unit% '  the GROUP  BY Sex
View Code

 

3) Having (packet after setting condition) 

Role: it is behind Group By clause to set conditions

So what is the difference between it and Where?

 

 

 The following sample code, is greater than the number of selected department 10

SELECT DeptName,COUNT(WorkNo) FROM  S_A_User GROUP BY DeptName HAVING COUNT(WorkNo)>=10

 

SELECT DeptName,COUNT(*) FROM S_A_User
WHERE Sex='Male'
GROUP BY DeptName HAVING COUNT(*)>10
Statistics males outnumber men 10 departments

 

4) into (out of the query results into a table (temporary table))

SELECT *
INTO #tmpwork
FROM S_A_User
WHERE Sex='Male'

#tmpwork The # denotes a temporary table;

Temporary tables and table of basic differences:

Temporary tables exist only when the second query, the query is closed, the data in the temporary table to clear.

 

to sum up

 

 

 

End

Guess you like

Origin www.cnblogs.com/LeeSki/p/12303776.html