Skip to main content

SQL Interview Questions- Oracle - Find top 2 department that contains more employees

Enter into mysql by using below command

mysql

Step1: Create a database by using below query.

mysql> create database nippo;

Step 2: List down the databases and check the created database is available or not.

mysql> show databases;

Step 3: Move within the database using below command.

mysql> use nippo;

Step 4: Create a table called employee.

mysql> create table employee (id int primary key auto_increment, dept_name varchar(255), name varchar(255));

Step 6: Check the given columns and attributes exactly available in the table.
mysql> desc employee;

Step 5: Insert the values in the table.
mysql> insert into employee values(NULL, 'infra', 'mika');
mysql> insert into employee values(NULL, 'infra', 'soomu');
mysql> insert into employee values(NULL, 'infra', 'mulla');
mysql> insert into employee values(NULL, 'support', 'maari');
mysql> insert into employee values(NULL, 'support', 'deva');
mysql> insert into employee values(NULL, 'client', 'victas');

Step 7: Command to fetch top 2 departments where highest employees present.
mysql> select dept_name, count(dept_name) as dept_count from employee group by dept_name order by dept_count desc limit 2;



That's it. Hope it helps.

Comments

Popular posts from this blog

AWS - EC2 Instance Start / Stop using AWS Lambda Python

Steps to Setup Lambda to Start / Stop EC2 instances: 1) Create a Lambda Function with 'Author from scratch' and with Function name 'ecStartInstance' and Runtime 'Python 3.8' 2) Choose new role with basic Lambda permission 3) Create policy using IAM role 4) Click on JSON Editor option and update EC2 instance policy json and click on 'Review Policy' JSON: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "ec2:Start*", "ec2:Stop*" ], "Resource": "*" } ] } 5) Give name ...

NASA's EMIT - Mineral dust investigator

Installing Postgres using Docker Container - Ubuntu 18.04

 Step1: Install Docker using Ubuntu Terminal Command: sudo apt install docker.io Step 2: Check docker is available command: docker Step 3: Check Docker Service is up and running. command: sudo service docker status Step 4: Pull latest postgres into docker command: docker pull postgres Step 5: check docker image is available cmd: docker images Step 6: Run the docker postgres image and validate container started running. cmd: sudo docker run --name psql-ultra -e POSTGRES_PASSWORD=master -d postgres sudo docker ps Note: postgres port 5432 and ubuntu 5432 tcp port has to get update. So normal -p command with docker won't work. Hope this helps!