Skip to main content

SQL Interview Question - 5


Consider a table named sales that stores information about sales transactions. The table has the following columns:

  • transaction_id: The unique identifier for each transaction.
  • transaction_date: The date when the transaction occurred.
  • amount: The amount of the transaction.

Write a SQL query to calculate the cumulative sum of sales amounts for each day, ordered by transaction date.

Sample Table:

CREATE TABLE sales (
    transaction_id INT,
    transaction_date DATE,
    amount DECIMAL(10, 2)
);

INSERT INTO sales (transaction_id, transaction_date, amount) VALUES
(1, '2024-03-01', 100),
(2, '2024-03-01', 150),
(3, '2024-03-02', 200),
(4, '2024-03-03', 50),
(5, '2024-03-03', 300),
(6, '2024-03-04', 100);

Solution:

SELECT 
    transaction_date,
    amount,
    SUM(amount) OVER (ORDER BY transaction_date) AS cumulative_sum
FROM 
    sales
ORDER BY 
    transaction_date;

 

Share your alternate solution in comments.


Success Stories



See all the Success Stories - here
Testimonials - here


You can check out other TakeOff Talent offerings that have helped 7,000+ people land jobs.

Offerings
📄 CV Review
📘 200 most-asked SQL interview questions with detailed solutions
📘 200 most-asked Python interview questions with detailed solutions
📊 SQL Crash Course
✍️ CV Writing for freshers
✍️ CV Writing
🛠️ Portfolio Project
🗣️ English Speaking Practice (Live 1:1)
🎯 Job Search Mentorship Package

  In case of any questions around services above, write to us at vibhanshu@takeofftalent.com

  Connect with our founder on Linkedin - https://www.linkedin.com/in/vibvibgyor/



Video Gallery



Check more videos here>>.

Other popular job openings

IDFC FIRST Bank is hiring for a fresher entry level Business Analyst role in India

Position: Business Analyst Company: IDFC FIRST Bank Location: Thane, Maharashtra, India Job type: Full-time Job mode: Onsite Job requisition id: P-191165 Years of experience: Fresher to 3 years Company description IDFC FIRST Bank was formed in December 2018 after the merger of IDFC Bank, an infrastructure finance giant, and Capital First, a retail finance specialist. The combined entity has created a robust and ethical commercial banking institution in India that emphasizes technology-led, customer-focused, and socially responsible banking practices. The bank commenced commercial operations in 2016 and has since established itself as a universal bank offering a wide spectrum of financial products. Services include Retail Banking, MSME Banking, Rural and Startup Finance, Cash and Wealth Management, Deposits, Corporate and Government Banking, Working Capital solutions, Trade Finance, and Treasury Services. IDFC FIRST Bank stands out for...

United Airlines is hiring for a fresher entry level Associate Data Analyst role in India

Position: Associate Data Analyst - Operations Performance & Analytics Company: United Airlines Business Services Pvt. Ltd (A wholly owned subsidiary of United Airlines Inc.) Location: Gurugram, Haryana, India Job Type: Full-time Job Mode: Onsite Job Requisition ID: GGN00002218 Years of Experience: 0-1 year Company Description United Airlines is one of the world’s leading aviation companies, recognized for its extensive route network and commitment to operational excellence. With a workforce of more than 100,000 professionals, United focuses on delivering safe, efficient, and reliable air travel to millions of passengers worldwide. The company values innovation, customer satisfaction, and global connectivity, operating across continents with a mission to unite people and cultures. United Airlines Business Services Pvt. Ltd, based in India, is a key extension of this mission, supporting various global functions including analytics, operations, technology, a...

Corsearch is hiring for a REMOTE fresher entry level Data Analyst role in India

Position: Data Analyst Company: Corsearch Location: Mumbai, India Job type: Full-time Job mode: Fully Remote Job requisition id: Not specified Years of experience: 0-3 years Company Description Corsearch is a global leader in trademark and brand protection, empowering organizations to safeguard their brand reputation and assets in the modern digital world. Established in 1949, Corsearch has evolved into a trusted partner for more than 5,000 global customers, including 73 of the Fortune 100 companies. The company combines AI-driven data, advanced analytics, and human expertise to help brands monitor and combat counterfeiting, infringement, and other fraudulent activities. Its mission is centered around building a world where consumers can confidently trust the brands they engage with. Corsearch’s proprietary technology suite helps companies manage trademark clearance, online brand protection, and anti-piracy operations across global markets. With over 1,...

Rockwell Automation is hiring for a fresher entry level Data Analyst role in India

Position: Data Analyst – Data Analytics & Insights (DA&I) Company: Rockwell Automation, Inc. Location: Pune, Noida, and Bangalore, India Job Type: Full-time Job Mode: Hybrid Job Requisition ID: R25-6074 Years of Experience: 0–3 years (Entry Level) Company Description: Rockwell Automation is one of the most respected names in the field of industrial automation and digital transformation. With a workforce of around 28,000 employees across more than 100 countries, the organization focuses on transforming industries through technology-driven innovation. Its mission revolves around connecting people’s creativity and problem-solving ability with advanced technology to create sustainable progress for industries and communities around the world. The company is headquartered in Milwaukee, Wisconsin, but has strong operational footprints across India, the United States, and other global markets. Rockwell Automation serves clients in manufacturing, energy, he...

General Mills is hiring for a fresher entry level Data Analyst (Business Intelligence) role in India

Position: Data Analyst – Business Intelligence, GIC SC Analytics Company: General Mills India Center (GIC) Location: Mumbai, India Job Type: Full-time Job Mode: Hybrid Job Requisition ID: 34466 Years of Experience: 0–1.5 years Company Description General Mills is a global food company known for creating some of the world’s most loved brands across more than 100 countries. Founded in 1866, the organization has a strong history of innovation and social responsibility. It operates with the philosophy that making food people love goes hand-in-hand with creating positive impact for the planet and communities. The company’s diverse product portfolio includes Cheerios, Pillsbury, Häagen-Dazs, Betty Crocker, and Nature Valley. Each brand holds a special place in homes worldwide. General Mills India Center (GIC), based in Mumbai, is the company’s global capability hub. It plays a key role in supporting global operations across supply chain, digital technology, consume...

IBM is hiring for a fresher entry level AI Research Intern role in India

Position: Research Intern - AI Company: IBM Location: Gurgaon, Haryana, India Job Type: Full-time Job Mode: On-site Job Requisition ID: Not specified Years of Experience: 0–3 years (College students/Fresher/Entry-level eligible) Company Description IBM, founded in 1911, has grown into one of the most influential technology corporations in the world, recognized for its consistent contributions to computing, software, and consulting. Since its establishment in India in 1992, IBM has become a leading force in transforming industries across the nation. Its diverse solutions cover financial services, healthcare, education, telecommunications, government, and automotive sectors. The company’s Indian operations serve as a critical component of IBM’s global ecosystem, focusing on hybrid cloud, artificial intelligence, and automation technologies. IBM collaborates closely with major corporations and public institutions to enable digital transformation through advanced...

NTT DATA North America is hiring for a fresher entry level Data Analyst role in India

Position: Data & Business Insights Associate (Data Analyst) Company: NTT DATA North America Location: Chennai, Tamil Nadu, India Job type: Full-time Job mode: On-site Job requisition id: Not specified Years of experience: 0–3 years (college students in final year can also apply) Company Description NTT DATA North America is part of NTT DATA, one of the world’s most recognized IT and business services firms. The organization supports clients across multiple industries by offering end-to-end solutions in business consulting, digital transformation, cloud strategy, artificial intelligence, and IT infrastructure management. With its North American headquarters serving as a strategic hub, the company emphasizes technological innovation, data-driven decision-making, and sustainable development. The firm’s operations span more than 50 countries, employing experts with diverse backgrounds and skill sets. It serves around 75% of the Fortune Global 100 companies...

Hiring for a Full-Stack Software Engineer for one of our clients at TakeOff Talent

Company: A leading product startup in AI Security Space (one of our Clients) Position: Full-Stack Engineer Experience: 2+years Location: Bengaluru, India - Onsite Job ID: TOT2025102 Company Overview We're a seed‑stage startup headquartered in San Francisco and Bangalore, building the world's most advanced security tooling for Gen AI systems. Our mission is to secure AI agents, chatbots, assistants, and copilots by proactively surfacing existing vulnerabilities before attackers can exploit them. Our flagship produc, is the industry's first fully‑autonomous red‑teaming agent for GenAI applications: relentlessly stress‑testing apps and models, breaking defenses, and guiding teams to stronger safeguards. We open‑source much of our frontier research and believe in shipping fast, rapidly experimenting and leading innovation in the domain of AI Security and Safety. We’re backed by credible investors and are focused on building foundational systems in a fast-growing and critical sp...

IndiGo Airlines is hiring for a fresher entry level Executive - Data Analytics role in India

Position: Executive - Data Analytics (as per JD, we see a mix of DA and DS skills) Company: IndiGo (InterGlobe Aviation Ltd) Location: Gurgaon, Haryana, India Job type: Full-time Job mode: Onsite Job requisition id: Not specified Years of experience: 0–3 years Company Description IndiGo, a subsidiary of InterGlobe Aviation Ltd, is India’s largest passenger airline known for its consistent punctuality, low fares, and efficient service. Since its inception in August 2006, IndiGo has grown from operating a single aircraft to maintaining a robust fleet exceeding 400 aircraft. The company operates more than 130 destinations, including over 90 domestic and 40 international routes. IndiGo emphasizes simplicity, affordability, and reliability, becoming a preferred choice for millions of passengers. It has developed an operational model focused on high reliability, rapid turnaround, and superior customer service. The organization continues to invest heavily in t...

Magna Powertrain is hiring for a fresher entry level Engineer Generative AI role in India

Position: Engineer Generative AI Company: Magna Powertrain (A division of Magna International) Location: Bangalore, India Job Type: Full-time Job Mode: Onsite Job Requisition ID: R00214397 Years of Experience: 0–3 years Company Description: Magna Powertrain is part of Magna International, a leading global automotive supplier committed to transforming mobility through innovation and sustainability. The company is known for producing advanced powertrain systems that make vehicles cleaner, safer, and more efficient. Magna Powertrain’s work combines expertise in mechanical engineering, data science, and intelligent automation to create products that meet global safety and environmental standards. With operations in several regions including India, North America, and Europe, the company focuses on continuous improvement and the integration of next-generation technologies. Magna emphasizes innovation, diversity, and collaboration, encouraging employees to think ...