---
title: "Mainframe – SQL Challenge -1"
description: "https://srinimf.com/2014/08/16/sql-queries-30-days-challenge-day-1/. Question 1 : Get maximum salaries department wise? Sol: SELECT DeptID, MAX(Salary) FROM EmpDetails GROUP BY DeptID. Question 2 : Wr..."
url: https://srinimf.com/2014/08/20/mainframe-sql-challenge-1/
date: 2014-08-20
modified: 2026-10-10
author: "Srini"
categories: ["Quiz", "SQL"]
tags: ["SQL tips and tricks"]
type: post
lang: en
---

# Mainframe – SQL Challenge -1

[![Mainframe-SQL](https://i0.wp.com/srinimf.com/wp-content/uploads/2014/08/untitled3.png?resize=150%2C120)](https://i0.wp.com/srinimf.com/wp-content/uploads/2014/08/untitled3.png?ssl=1)*Mainframe-SQL*

Related[SQL Queries 30 Days Challenge – Day 1](https://srinimf.com/2014/08/16/sql-queries-30-days-challenge-day-1/)

**Question 1****:**

**Get maximum salaries department wise?**

Sol: SELECT DeptID, MAX(Salary) FROM EmpDetails GROUP BY DeptID

**Question 2****:**

**Write COBOL logic to get nth prime number?**

IDENTIFICATION DIVISION.

PROGRAM-ID. PRIME.

AUTHOR. XYZ.

DATE-WRITTEN. JULY 2014.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SOURCE-COMPUTER. IBM-370 WITH DEBUGGING MODE.

DATA DIVISION.

WORKING-STORAGE SECTION.

01 WS-VAR.

10 WS-INPUT PIC 9(04) VALUE ZEROES.

10 WS-OUT PIC 9(04) VALUE ZEROES.

10 WS-TEMP-1 PIC 9(4) VALUE 0.

10 WS-TEMP-2 PIC 9(4) VALUE 0.

10 WS-TEMP-3 PIC 9(4) VALUE 0.

10 WS-TEMP-4 PIC 9(4) VALUE 0.

10 WS-TEMP-5 PIC 9(4) VALUE 0.

PROCEDURE DIVISION.

ACCEPT WS-INPUT.

DISPLAY ‘INPUT:’ WS-INPUT

MOVE 1 TO WS-TEMP-1

MOVE 2 TO WS-OUT

MOVE 2 TO WS-TEMP-2

IF WS-TEMP-1 = WS-INPUT

DISPLAY WS-INPUT ‘TH PRIME NO IS:’ WS-OUT

GO TO 500-PARA

ELSE

COMPUTE WS-OUT = WS-OUT + 1

PERFORM 100-PARA

END-IF.

100-PARA.

PERFORM 200-PARA UNTIL WS-TEMP-2 >= WS-OUT

PERFORM 300-PARA.

200-PARA.

DIVIDE WS-OUT BY WS-TEMP-2 GIVING WS-TEMP-3

REMAINDER WS-TEMP-4

IF WS-TEMP-4 = 0

COMPUTE WS-OUT = WS-OUT + 1

MOVE 2 TO WS-TEMP-2

ELSE

COMPUTE WS-TEMP-2 = WS-TEMP-2 + 1

END-IF

GO TO 100-PARA.

300-PARA.

COMPUTE WS-TEMP-1 = WS-TEMP-1 + 1

IF WS-TEMP-1 = WS-INPUT

DISPLAY WS-INPUT ‘TH PRIME NO IS:’ WS-OUT

GO TO 500-PARA

ELSE

COMPUTE WS-OUT = WS-OUT + 1

MOVE 2 TO WS-TEMP-2

GO TO 100-PARA

END-IF.

500-PARA.

DISPLAY WS-OUT

STOP RUN.

**Question 3****:**

**Get employee details where salaries equal in each department?**

SELECT * FROM employees e1

WHERE e1.employee_id = ( SELECT employee_id

FROM employees e2

WHERE e2.department_id = e1.department_id

AND e2.salary = e1.salary);

**Question 4:**

**Select employee details , who do not have supervisor?**

Select * from emp where supervisor is null.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2014%2F08%2F20%2Fmainframe-sql-challenge-1%2F&media=http%3A%2F%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2014%2F08%2Funtitled3.png%3Fw%3D150&description=Mainframe%20-%20SQL%20Challenge%20-1)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2014/08/20/mainframe-sql-challenge-1/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2014/08/20/mainframe-sql-challenge-1/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2014/08/20/mainframe-sql-challenge-1/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2014/08/20/mainframe-sql-challenge-1/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Mainframe%20-%20SQL%20Challenge%20-1&body=https%3A%2F%2Fsrinimf.com%2F2014%2F08%2F20%2Fmainframe-sql-challenge-1%2F&share=email)
-

### Like this:

Like Loading…
