-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL09Test.sql
More file actions
44 lines (39 loc) · 1.04 KB
/
SQL09Test.sql
File metadata and controls
44 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--Jose Guadarrama
--11/18/2014
--1
Select OrderNo,
ClientNo,
InvoiceAmt
From Guadarrama.Orders
Where InvoiceAmt >= (Select Avg(InvoiceAmt)
From Guadarrama.Orders);
--2
Select ClientNo,
Name,
BalDue
From Guadarrama.Clients
Where BalDue >= (Select Avg(BalDue)
From Guadarrama.Clients);
--3
Select ClntTable.ClientNo,
ClntTable.Name,
ClntTable.BalDue
From Guadarrama.Clients As ClntTable
Where ClntTable.BalDue > 100 And 250 <= (Select Sum(InvoiceAmt)
From Guadarrama.Orders As OrdTable
Where ClntTable.ClientNo = OrdTable.ClientNo);
--4
Select ClientNo, "MinInvoiceAmt", "MaxInvoiceAmt"
From(Select ClientNo,
Min(InvoiceAmt) As "MinInvoiceAmt",
Max(InvoiceAmt) As "MaxInvoiceAmt"
From Guadarrama.Orders
Group By ClientNo) As AmountsMinMax
Where "MinInvoiceAmt" <= 100
And "MaxInvoiceAmt" >= 500;
--5
Update Guadarrama.Clients
Set BalDue = BalDue + (Select Sum(InvoiceAmt)
From Guadarrama.Orders
Where Clients.ClientNo = Orders.ClientNo)
Where ClientNo < 10016;