MS SQL-Server 2000. Сивохин А.В. - 44 стр.

UptoLike

Составители: 

Select type, SUM(price), count = COUNT(*) -- имя счетчика count
From titles
Where type < 'ps'
Group By ALL type --6 строк
-- строки с type >= 'ps'- без агрегирования
Select type, pub_id, SUM(price), COUNT(*)
From titles
Where price <> 0
Group By type, pub_id --7 агрегированных строк
Select type, pub_id, SUM(price), COUNT(*)
From titles
Where price <> 0
Group By type, pub_id With Cube --суперагрегирование
Select type, pub_id, SUM(price), COUNT(*)
From titles
Where price <> 0
Group By type, pub_id --13 строк
With ROLLUP
V)Объединение таблиц с помощью раздела UNION:
USE Northwind
Select City, Phone Info #Tab1 From customers
Where contacttitle = 'Marketing Assistant'
Select City, Phone Info #Tab 2 From Customers
Where contacttitle = 'Sales Associate'
Selest City, Phone From #Tab1
UNION
Select City, Phone From #Tab2
W)Использование раздела ORDER BY:
USE Northwind
Select ContactTitle, City From Customers
Where ContactTitle IN ('Marketing Assistant'
'Sales Agent'
'Sales Associate')
Order By ContactTitle,City --18 строк
X)Использование раздела COMPUTE:
Select title_id, price From Titles
Where (type = 'bisiness') OR (type = 'mod_cook')
Compute SUM(price), COUNT(price) --6строк и
-- SUM
-- =====
--77.9000
-- CNT
-- =====
-- 6 --всего 7строк
Select title_id, price From Titles
Where (type = 'business') OR (type = 'mod_cook')
Order By type
Compute Count(price), Sum(Price) By type
Y)Обработка данных с помощью команды UPDATE:
Declare @@Var1 int
Select type, SUM(price), count = COUNT(*) -- имя счетчика count
  From titles
  Where type < 'ps'
  Group By ALL type                            --6 строк
-- строки с type >= 'ps'- без агрегирования
Select type, pub_id, SUM(price), COUNT(*)
  From titles
  Where price <> 0
  Group By type, pub_id                  --7 агрегированных строк

Select type, pub_id, SUM(price), COUNT(*)
  From titles
  Where price <> 0
  Group By type, pub_id With Cube     --суперагрегирование
Select type, pub_id, SUM(price), COUNT(*)
From titles
Where price <> 0
  Group By type, pub_id               --13 строк
  With ROLLUP

V)Объединение таблиц с помощью раздела UNION:
USE Northwind
Select City, Phone Info #Tab1 From customers
  Where contacttitle = 'Marketing Assistant'
Select City, Phone Info #Tab 2 From Customers
  Where contacttitle = 'Sales Associate'
Selest City, Phone From #Tab1
UNION
Select City, Phone From #Tab2

W)Использование раздела ORDER BY:
USE Northwind
Select ContactTitle, City From Customers
  Where ContactTitle IN ('Marketing Assistant'
                    'Sales Agent'
                    'Sales Associate')
  Order By ContactTitle,City                   --18 строк

X)Использование раздела COMPUTE:
Select title_id, price From Titles
  Where (type = 'bisiness') OR (type = 'mod_cook')
  Compute SUM(price), COUNT(price)             --6строк и

                                               -- SUM
                                               -- =====
                                               --77.9000
                                               -- CNT
                                               -- =====
                                   -- 6        --всего 7строк
Select title_id, price From Titles
  Where (type = 'business') OR (type = 'mod_cook')
  Order By type
  Compute Count(price), Sum(Price) By type

Y)Обработка данных с помощью команды UPDATE:
Declare @@Var1 int