SQL Interview Questions:1

1. Finding last Transaction of each person along with total no of transaction by each person. by using below table 

create table customers

(

id int,

name varchar(1000),

TransactionDate datetime

)

insert into customers values(1,'vineela','2023-01-04 03:30:30'),

(1,'vineela','2023-01-04 04:30:30'),

(2,'hemanth','2023-01-04 2:30:30'),

(1,'vineela','2023-01-04 06:30:30'),

(2,'hemanth','2023-01-04 06:30:30'),

(1,'vineela','2023-01-04 08:30:30'),

(2,'hemanth','2023-01-04 09:00:30'),

(1,'vineela','2023-01-04 09:30:30'),

(2,'hemanth','2023-01-04 12:00:30')

select * from customers

query:-

select id, name, count(id) as no_of_Transactions ,max(TransactionDate) as last_Transaction_Date from customers group by id, name order by id


Comments

Popular posts from this blog

SQL Interview Questions:3

AZURE DATA FACTORY INTERVIEW QUESTIONS: FILES FORMATS

AZURE DATA FACTORY INTERVIEW QUESTIONS :ACTIVITIES AND TYPES.