Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
19 views
4 pages
SQL Interview
Uploaded by
aditya3662
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save SQL Interview For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
19 views
4 pages
SQL Interview
Uploaded by
aditya3662
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save SQL Interview For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save SQL Interview For Later
You are on page 1
/ 4
Search
Fullscreen
SQL Interview Question asked in q > > HsBcProblem Statement Write a SQL query to find the average transaction amount for each account, but only for those accounts where the average transaction amount exceeds the overall average transaction amount across all accounts. Also, include the account name in the result set. Input account_id — transaction_date amount 101 2024-01-01 1000.00 101 2024-01-02 1200.00 102 2024-01-03 800.00 102 2024-01-04 1500.00 103 2024-01-05 2000.00 103 2024-01-06 900.00 Output account_id Avg_amountTable Creation and Data Insertion script ----Table creation Script CREATE TABLE transactions ( account_id INT, transaction_date DATE NOT NULL, amount DECIMAL(10, 2) NOT NULL, ) --Data Insertion Script INSERT INTO transactions (account_id, transaction_date, amount) VALUES (101,'2024-01-01', 1000.00), (101,'2024-01-02', 1200.00), (102,'2024-01-03', 800.00), (102,'2024-01-04', 1500.00), (103,'2024-01-05', 2000.00), (103,'2024-01-06', 900.00) Table Transactions transaction_date amount | 2024-01-01 1000.00 2024-01-02 1200.00 2024-01-03 800.00 2024-01-04 1500.00 2024-01-05 2000.00 2024-01-06 900.00Solution =select account_id,avg(amount) Avg_amount from transactions t group by account_id having avg(amount)>(select avg(amount) from transactions)| % + Results gil Messages account_id _ Avg_amount 103 | 1450.000000 SQL Script select account_id,avg(amount) Avg_amount from transactions t group by account_id having avg(amount)>(select avg(amount) from transactions) Explanation e First part is to calculate average amount across accounts. Simply using avg() function with grouping by account_id will fetch account wise averge values. © Second part is to figure out overall average value. We can achieve it using avg() function across table. no group by clause needed here. Third part is to compare and find out which accounts are performing better than overall average. We have used having clause against a sub query that returns overall average.
You might also like
Paypal Data Analyst Interview Questions
PDF
No ratings yet
Paypal Data Analyst Interview Questions
20 pages
DBMS Practicals
PDF
No ratings yet
DBMS Practicals
32 pages
Lecture Notes For DBMS: Set Operations
PDF
No ratings yet
Lecture Notes For DBMS: Set Operations
3 pages
250+ TOP MCQs On SQL Queries and Answers - Quiz
PDF
No ratings yet
250+ TOP MCQs On SQL Queries and Answers - Quiz
1 page
Comp 5311 Database Management Systems: 4. Structured Query Language 2
PDF
No ratings yet
Comp 5311 Database Management Systems: 4. Structured Query Language 2
11 pages
PhonePe Data Analyst Interview Questions
PDF
No ratings yet
PhonePe Data Analyst Interview Questions
21 pages
SQL - Table of Contents 1 Concepts/Facts 3 DDL 3
PDF
No ratings yet
SQL - Table of Contents 1 Concepts/Facts 3 DDL 3
20 pages
Assignment 1
PDF
No ratings yet
Assignment 1
1 page
Aggregation
PDF
No ratings yet
Aggregation
8 pages
SUBQUERIES - Basics
PDF
No ratings yet
SUBQUERIES - Basics
8 pages
Accelerating OpenERP Accounting
PDF
No ratings yet
Accelerating OpenERP Accounting
27 pages
Performance DBA Example Schema
PDF
No ratings yet
Performance DBA Example Schema
1 page
Solutions ProjectMissingMoneyMatters
PDF
No ratings yet
Solutions ProjectMissingMoneyMatters
5 pages
Take - Home - Test 1
PDF
No ratings yet
Take - Home - Test 1
11 pages
Transaction
PDF
No ratings yet
Transaction
2 pages
Basic SQL Interview Questions
PDF
No ratings yet
Basic SQL Interview Questions
17 pages
Bank
PDF
No ratings yet
Bank
14 pages
Lab 04
PDF
No ratings yet
Lab 04
5 pages
DBMS Manual (18 SCHEME) - 221213 - 173230-1
PDF
No ratings yet
DBMS Manual (18 SCHEME) - 221213 - 173230-1
15 pages
04OLAP
PDF
No ratings yet
04OLAP
121 pages
Experiment 05
PDF
No ratings yet
Experiment 05
3 pages
List The Minimum Account Balance
PDF
No ratings yet
List The Minimum Account Balance
2 pages
Data Analyst SQL Task
PDF
No ratings yet
Data Analyst SQL Task
2 pages
Analytic Functions in Oracle
PDF
No ratings yet
Analytic Functions in Oracle
35 pages
1688925241852
PDF
No ratings yet
1688925241852
5 pages
ICE305-LAB4 Suraiya Salam
PDF
No ratings yet
ICE305-LAB4 Suraiya Salam
10 pages
TD Advanced SQL
PDF
No ratings yet
TD Advanced SQL
88 pages
Homework Assignment 10
PDF
No ratings yet
Homework Assignment 10
4 pages
Dbms Lab 4
PDF
No ratings yet
Dbms Lab 4
7 pages
Dbms Practical 3
PDF
No ratings yet
Dbms Practical 3
20 pages
Warehouse and SQL QUESTIONS
PDF
No ratings yet
Warehouse and SQL QUESTIONS
14 pages
Assignment No 2 SQL
PDF
No ratings yet
Assignment No 2 SQL
6 pages
1.10. Logical Operators
PDF
No ratings yet
1.10. Logical Operators
2 pages
Exp 6 - 7 - 8
PDF
No ratings yet
Exp 6 - 7 - 8
26 pages
CSE302 Lab03
PDF
No ratings yet
CSE302 Lab03
3 pages
Day3 Datanalyst
PDF
No ratings yet
Day3 Datanalyst
10 pages
Lab 04: SQL Functions & Regular Expressions: CSC-252: Database Management System
PDF
No ratings yet
Lab 04: SQL Functions & Regular Expressions: CSC-252: Database Management System
6 pages
Lecture Week 4-Databases
PDF
No ratings yet
Lecture Week 4-Databases
28 pages
SQL & Databases - Subqueries
PDF
No ratings yet
SQL & Databases - Subqueries
31 pages
Mysql Avg Function: John Ram Jack Jack Jill Zara Zara
PDF
No ratings yet
Mysql Avg Function: John Ram Jack Jack Jill Zara Zara
1 page
Oralcle Analytical Questions
PDF
No ratings yet
Oralcle Analytical Questions
26 pages
Data Analyst Cheat Sheet 1734117256
PDF
No ratings yet
Data Analyst Cheat Sheet 1734117256
32 pages
DBMS 6,7,8,9
PDF
No ratings yet
DBMS 6,7,8,9
22 pages
12 - May - Interview Question SQL Group By, Case When, Partition by
PDF
No ratings yet
12 - May - Interview Question SQL Group By, Case When, Partition by
17 pages
Gajanan
PDF
No ratings yet
Gajanan
23 pages
Bank SQL Examples and Dashboard
PDF
No ratings yet
Bank SQL Examples and Dashboard
4 pages
4 Group by Clause, Having Clause, Multiple Row (Or Group or Aggregate) Functions
PDF
100% (1)
4 Group by Clause, Having Clause, Multiple Row (Or Group or Aggregate) Functions
17 pages
SQL Template Guide
PDF
No ratings yet
SQL Template Guide
2 pages
Database Unit II
PDF
No ratings yet
Database Unit II
170 pages
SQL Answer Book
PDF
No ratings yet
SQL Answer Book
2 pages
Dbms Lab
PDF
No ratings yet
Dbms Lab
36 pages
'Jensen': Sum Sum Sum
PDF
No ratings yet
'Jensen': Sum Sum Sum
6 pages
Imp SQL Solved
PDF
No ratings yet
Imp SQL Solved
21 pages
SQL Functions
PDF
No ratings yet
SQL Functions
23 pages
11MARCH Assignment
PDF
No ratings yet
11MARCH Assignment
2 pages
February SQL Questions Compiled
PDF
No ratings yet
February SQL Questions Compiled
174 pages
Data Analysis With SQL: Postgresql Cheat Sheet
PDF
No ratings yet
Data Analysis With SQL: Postgresql Cheat Sheet
4 pages