0% found this document useful (0 votes)
37 views3 pages

Software Developer - SQL Coding Problems

The document describes two SQL problems involving employee attendance data. The first problem is to find the most and least regular employees based on attendance records. The second is to output a daily list of employees and their presence or absence. Sample data and database connection details are also provided.

Uploaded by

Sharnjit singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
37 views3 pages

Software Developer - SQL Coding Problems

The document describes two SQL problems involving employee attendance data. The first problem is to find the most and least regular employees based on attendance records. The second is to output a daily list of employees and their presence or absence. Sample data and database connection details are also provided.

Uploaded by

Sharnjit singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Problem 1

Most regular and more irregular employee

Table = employee
Example data:
Id (auto-inc primary key) Name

1 A

2 B

3 C

4 D

5 E

6 F

Attendance Register (attendance_register)


Id (auto-inc primary key) Employee Id Date

1 1 01/01/2021

2 2 01/01/2021

3 5 01/01/2021

4 6 01/01/2021

5 2 02/01/2021

6 3 02/01/2021

7 4 02/01/2021

8 2 03/01/2021

Write SQL queries to output the most regular (maximum attendance) and irregular employee
names.

Problem 2
Use the same tables as problem 1.
Write SQL query to output daily present/absent list like table below.
Date Employee Name Status

01/01/2021 A Present

01/01/2021 B Present

01/01/2021 C Absent

01/01/2021 D Absent

01/01/2021 E Present

01/01/2021 F Present

02/01/2021 A Absent

02/01/2021 B Present

… … …

Connecting to database
There is a public postgres database where you can try out your SQL queries.
Please do not delete the data or drop the tables.
If you are unable to connect please contact us.
● Host: heffalump.db.elephantsql.com
● Port: default (5432)
● User: llakhbgv
● Password: yEkAGp26fHEsCa-SyGwOZC0xqpx_wuBX
● Database: llakhbgv

If you would like to set up the database elsewhere you can use the following
scripts.

drop table if exists attendance_register;


drop table if exists employee;

create table employee


(
id SERIAL PRIMARY KEY,
name CHARACTER VARYING(255) not null
);

create table attendance_register


(
id SERIAL PRIMARY KEY,
employee_id int not null references employee(id),
recorded_date timestamp not null
);

insert into employee (name) values ('A');


insert into employee (name) values ('B');
insert into employee (name) values ('C');
insert into employee (name) values ('D');
insert into employee (name) values ('E');
insert into employee (name) values ('F');

insert into attendance_register (employee_id, recorded_date) values ((select id from employee


where name = 'A'), '2021-01-01');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'B'), '2021-01-01');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'E'), '2021-01-01');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'F'), '2021-01-01');

insert into attendance_register (employee_id, recorded_date) values ((select id from employee


where name = 'B'), '2021-01-02');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'C'), '2021-01-02');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'D'), '2021-01-02');

insert into attendance_register (employee_id, recorded_date) values ((select id from employee


where name = 'B'), '2021-01-03');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'C'), '2021-01-03');
insert into attendance_register (employee_id, recorded_date) values ((select id from employee
where name = 'F'), '2021-01-03');

You might also like