Разработка и сопровождение баз данных в среде СУБД MS SQL Server 2000. Сивохин А.В - 109 стр.

UptoLike

Select discounts.stor_id, discounts.discounttype, stores.stor_name
From discounts RIGHT OUTER JOIN stores
ON discounts.stor_id = stores.stor_id --6 строк
Задание 1.6.12. Использование разделов GROUP BY и HAVING.
Select type, SUM(price), COUNT(*)
From titles
Group By type
Select type, SUM(price), count = COUNT(*)
Form titles
Where type < 'ps'
Group BY type
Select type, SUM(price), count = COUNT(*)
From titles
Where type < 'ps'
Group By ALL type
Select type, pub_id, SUM(price), COUNT(*)
From titles
Where price <> 0
Group By type, pub_id
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
With ROLLUP
Задание 1.6.13. Объединение таблиц с помощью раздела 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
Select discounts.stor_id, discounts.discounttype, stores.stor_name
From discounts RIGHT OUTER JOIN stores
ON discounts.stor_id = stores.stor_id             --6 строк

Задание 1.6.12. Использование разделов GROUP BY и HAVING.
Select type, SUM(price), COUNT(*)
From titles
Group By type

Select type, SUM(price), count = COUNT(*)
  Form titles
  Where type < 'ps'
  Group BY type

Select type, SUM(price), count = COUNT(*)
  From titles
  Where type < 'ps'
  Group By ALL type

Select type, pub_id, SUM(price), COUNT(*)
  From titles
  Where price <> 0
  Group By type, pub_id

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
  With ROLLUP

Задание 1.6.13. Объединение таблиц с помощью раздела 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