Mandalika has Published 470 Articles

Write a SQL query to count the number of duplicate TRANSACTION_ID in an ORDERS DB2 table

Mandalika

Mandalika

Updated on 01-Dec-2020 04:39:32

2K+ Views

We can find the duplicate TRANSACTION_ID in the ORDERS DB2 table using the below query:ExampleSELECT TRANSACTION_ID, COUNT(*) AS TRANSACTION_COUNT FROM ORDER GROUP BY TRANSACTION_ID HAVING COUNT(*) > 1The purpose of COUNT(*) is to count the number of rows. We will group the result based on the TRANSACTION_ID using GROUP BY ... Read More

Explain SQL describing COUNT aggregate and CURRENT DATE function

Mandalika

Mandalika

Updated on 01-Dec-2020 04:38:41

392 Views

Problem: Write a SQL query to count the number of orders which were placed today from the ORDERS DB2 table. (The date should not be hardcoded)SolutionWe can find the count of orders which are placed today using the below DB2 query:ExampleSELECT COUNT(ORDER_ID) AS ORDER_COUNT FROM ORDERS WHERE ORDER_DATE = CURRENT ... Read More

Example of SQL query describing the conditional processing

Mandalika

Mandalika

Updated on 30-Nov-2020 09:42:48

257 Views

Problem: Write a SQL query to display 2 columns. First column should have ORDER_ID, the second column should give the value as YES/NO for free shipping based on ORDER_TOTAL > 500.SolutionThe query to display ORDER_ID and free shipping result based on the ORDER_TOTAL criteria can be written as below.ExampleSELECT ORDER_ID, ... Read More

Investigation of root cause and resource responsible for the deadlock in DB2

Mandalika

Mandalika

Updated on 30-Nov-2020 09:41:18

2K+ Views

Problem: A COBOL-DB2 program failed due to deadlock. How will you find the resource due to which the program failed?SolutionA DEADLOCK condition occurs when two or more applications are stuck, waiting for each other to release the locks on the resources needed by them. A detailed information and logs can ... Read More

Explain the concept of LOCK PROMOTION with the help of an example

Mandalika

Mandalika

Updated on 30-Nov-2020 09:40:03

709 Views

A DB2 LOCK PROMOTION is defined as the process of acquiring more restrictive locks on a particular resource. DB2 uses LOCK PROMOTION for the concurrent processes which are trying to access the same DB2 resource. Basically, there are three types of locks.Shared lock(S)The concurrent processes can place a shared lock ... Read More

Implementation and purpose of direct index look-up

Mandalika

Mandalika

Updated on 30-Nov-2020 09:38:27

204 Views

The direct index look-up is chosen by the DB2 optimizer when all the columns used in the predicate of the WHERE clause is part of the index.For example, if we have ORDERS DB2 table as below.ORDER_IDORDER_DATEORDER_TOTALZ2234530-10-2020342Z3341214-08-2020543Z5699019-10-2020431Z5690221-09-20206743Z9978104-11-2020443Z5611229-08-2020889In this table, there is one index which is built having columns named ORDER_ID and ... Read More

What is the SQL query describing usage of MAX aggregate function and GROUP-BY with HAVING?

Mandalika

Mandalika

Updated on 30-Nov-2020 09:37:27

250 Views

We can find the highest ORDER_TOTAL datewise from the ORDERS DB2 table using below query.ExampleSELECT ORDER_DATE, MAX(ORDER_TOTAL) FROM ORDERS GROUP BY ORDER_DATEWe will use ‘GROUP BY’ on ORDER_DATE to group the result date wise and MAX aggregate function will help us to get the maximum ORDER_TOTAL placed at that particular ... Read More

Write the DB2 SQL query to find the third highest ORDER_TOTAL in a ORDERS DB2 table

Mandalika

Mandalika

Updated on 30-Nov-2020 09:36:25

668 Views

We can find the third highest ORDER_TOTAL in the ORDERS DB2 table using the below query.ExampleSELECT ORDER_ID, MIN(ORDER_TOTAL) FROM ORDERS    ORDER BY ORDER_TOTAL DESC    FETCH FIRST 3 ROWS ONLYThe ‘FETCH FIRST 3 ROWS ONLY’ clause will give only 3 rows in the output and these 3 rows will ... Read More

SQL query describing usage of SUM aggregate function and GROUP-BY with HAVING

Mandalika

Mandalika

Updated on 30-Nov-2020 09:35:05

343 Views

Problem: Write the DB2 SQL query to give the sum of ORDER_TOTAL for the orders placed on 29th July and 30th July individually. The result should come in a single table.SolutionWe can find the sum of ORDER_TOTAL for the orders placed on 29th and 30th July individually using aggregate function ... Read More

Example and usage of JOINS in DB2

Mandalika

Mandalika

Updated on 30-Nov-2020 09:34:02

1K+ Views

Problem: How will you find the ORDER_ID, TRANSACTION_ID and TRANSACTION_STATUS from ORDERS and TRANSACTIONS DB2 table using joins?SolutionWe can find ORDER_ID, TRANSACTION_ID and TRANSACTION_STATUS from ORDERS and TRANSACTIONS table using the INNER JOIN query.For example, if we have below 2 ORDERS table.ORDER_IDTRANSACTION_IDORDER_DATEZ22345ITX448923-10-2020Z62998ITX431121-10-2020Z56902ITX312026-10-2020 TRANSACTION_IDTRANS_AMTTRANSACTION_STATUSITX44891128PAIDITX43112318PAIDITX312088956UNPAIDITX21675612FAILEDWe can use an inner join query as below.ExampleSELECT ... Read More

Previous 1 ... 4 5 6 7 8 ... 47 Next
Advertisements