What statements do you need to know when learning DB2 databases?

Source: Internet
Author: User

This article mainly tells you about the 10 common statements that we must master when learning the DB2 database. The following is an article about how to learn the DB2 database, A detailed description of the 10 commonly used statements that we all need to understand.

Databases, statements, learning databases, statements, learning

1. Search for the employee's number, name, department, and date of birth. If the date of birth is null, the date is displayed as unknown and is sorted by department. The date format is yyyy-mm-dd.

 
 
  1. Select emp_no, emp_name, dept, isnull (convert (char (10), birthday, 120), 'date unknown ') birthday
  2. From employee
  3. Order by dept

2. Search for the names, gender, department, and title of employees in the same unit as Yu Ziqiang.

 
 
  1. Select emp_no, emp_name, dept, title
  2. From employee
  3. Where emp_name <> 'yu Ziqiang 'and dept in
  4. (Select dept from employee
  5. Where emp_name = 'yu Ziqiang ')

3. Collect the total salary of each department by department

 
 
  1. select dept,sum(salary)   
  2. from employee   
  3. group by dept  

4. Find the sales status of a product named 14-inch display, and display the number, quantity, unit price, and amount of the product.

 
 
  1. Select a. prod_id, qty, unit_price, unit_price * qty totprice
  2. From sale_item a, product B
  3. Where a. prod_id = B. prod_id and prod_name = '14-inch dashboard'

5. In the sales list, summarize the sales quantity and amount of each product by product number.

 
 
  1. select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice   
  2. from sale_item   
  3. group by prod_id  

6. Use the convert function to calculate the total order amount for each customer in 1996 by customer number

 
 
  1. select cust_id,sum(tot_amt) totprice   
  2. from sales   
  3. where convert(char(4),order_date,120)='1996'   
  4. group by cust_id  

7. Search for customer numbers, names, and total orders with sales records

 
 
  1. select a.cust_id,cust_name,sum(tot_amt) totprice   
  2. from customer a,sales b   
  3. where a.cust_id=b.cust_id   
  4. group by a.cust_id,cust_name  

8. Search for customer numbers, names, and total orders with sales records in June 1997

 
 
  1. select a.cust_id,cust_name,sum(tot_amt) totprice   
  2. from customer a,sales b   
  3. where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'   
  4. group by a.cust_id,cust_name   

9. Search for the largest sales record at a time

 
 
  1. select order_no,cust_id,sale_id,tot_amt   
  2. from sales   
  3. where tot_amt=   
  4. (select max(tot_amt)   
  5. from sales)  

10. Search for the salesperson list and sales date with at least three sales attempts

 
 
  1. select emp_name,order_date   
  2. from employee a,sales b   
  3. where emp_no=sale_id and a.emp_no in   
  4. (select sale_id   
  5. from sales   
  6. group by sale_id   
  7. having count(*)>=3)   
  8. order by emp_name   

The above content is an introduction to the Fifty-four common statements that DB2 databases must master. I hope you will gain some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.