0% found this document useful (0 votes)
46 views14 pages

EX Chuong3+4

Uploaded by

huytoa3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views14 pages

EX Chuong3+4

Uploaded by

huytoa3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Họ và tên: Nguyễn Huy Tỏa

MSV: 2251162175

CHƯƠNG 3

Bài 1: Write a SELECT statement that returns three columns from the Vendors
table: VendorContactFName, VendorContactLName, and VendorName. Sort
the result set by last name, then by first name.

Kết quả:
Bài 2: Write a SELECT statement that returns four columns from the Invoices
table. named Number, Total, Credits, and Balance: Number Column alias for
the InvoiceNumber column Total Column alias for the InvoiceTotal column
Credits Sum of the Payment Total and Credit Total columns Balance
InvoiceTotal minus the sum of Payment Total and Credit Total Use the AS
keyword to assign colum aliases.
Bài 3: Write a SELECT statement that returns one column from the Vendors
table named Full Name. Create this column from the VendorContactFName
and VendorContactLName columns. Format it as follows: last name, comma,
first name (for example. "Doe. John"). Sort the result set by last name. then
by first name.
Bài 4: Write a SELECT statement that returns three columns:

InvoiceTotal From the Invoices table

10% 10% of the value of InvoiceTotal

Plus 10% The value of InvoiceTotal plus 10%


(For example, if InvoiceTotal is 100.0000, 10% is 10.0000, and Plus 10% is
110.0000.) Only return those rows with a balance due greater than 1000.
Sort the result set by InvoiceTotal, with the largest invoice first.

Bài 5: Modify the solution to exercise 2 to filter for invoices with an


InvoiceTotal that's greater than or equal to $500 but less than or equal to
$10,000.
Bài 6: Modify the solution to exercise 3 to filter for contacts whose last name
begins with the letter A, B. C. or E.
Bài 7: Write a SELECT statement that determines whether the PaymentDate
column of the Invoices table has any invalid values. To be valid. PaymentDate
must be a null value if there's a balance due and a non-null value if there's
no balance due. Code a compound condition in the WHERE clause that tests
for these conditions

CHƯƠNG 4

Unless otherwise stated , use the explicit join syntax.

1.Write a SELECT statement that returns all columns from the Vendors table
inner joined-with the Inoices table.
2. Write a SELECT statement that returns four columns:

Vendor Name From the Vendors table

Invoice Number From the Invoices table

InvoiceDate From the Invoices table

Balance Invoice Total minus the sum of

Payment Total and CreditTotal

The result set should have one row for each invoice with a non-zero balance.

Sort the result set by VendorName in ascending order.


3. Write a SELECT statement that returns three columns:

VendorName From the Vendors table

DefaultAccountNo From the Vendors table

Account Description From the GLAccounts table

The result set should have one row for each vendor, with the account
number and account description for that vendor's default account number.
Sort the result set by Account Description, then by VendorName

Chanter 4 How to retrieve date from tro or more tahled


4. Generate the same result set described in exercise 2, but use the implicit
join syntax.
5. Write a SELECT statement that returns five columns from three tables, all
using column aliases:

Vendor VendorVame column

Date InvoiceDate column

Number InvoiceNumber column

# InvoiceSequence column

lincheth InvoiceLineItemAmount colums

Assian une tobowing corterton names to the tables.

v Vendors table

i Invoices tahle

li InvoiceLineltems table

Sort the final result set by Veror, Date, Number, and #.


6. Write a SELECT statement that returns three columns.

VendorID From the Vendors table

VendorName From the Vendors table

Name A concatenation of VendorContactF Name and VendorContactLName,


with a space in between

The result set should have one row for each vendor whose contact has the
same first name as another vendor's contact. Sort the final result set by
Name.

Hint: Use a self-join.

7. Write a SELECT statement that returns two columns from the GLAccounts
table: AccountNo and AccountDescription. The result set should have one
now for each account number that has never been used. Sort the hinal result
set by AccountNo.

Him: Use an outer join to the InvoiceLineltems table.

8. Use the UNION operator to generate a result set consisting of two columns
from the Vendors table: VendorName and VendorState. If the vendor is in
California, the VendorState value should be "CA"; otherwise, the Vendor State
value should he "Outside CA." Sort the final result set by Vendon Vame.

You might also like