Advanced SQL - Compare Product Sales for given months And Rank the Products based on Sales Growth

Поделиться
HTML-код
  • Опубликовано: 17 окт 2023
  • Episode 9 of 30: We will cover Advanced SQL - Compare Product Sales For Given Months (Get the Sales difference from previous month to current month) And Rank the Products based on Sales Growth. Below is the desired Create Tales Script and Sample Records that you can use to practice this Exercise with me. Pls Note: Below only provides sample records. Add more records if you like.
    -----------------------------------------------------------------------------------------------------------
    CREATE TABLE products (
    product_id INT PRIMARY KEY IDENTITY(1,1),
    product_name VARCHAR(255) NOT NULL,
    supplier_id INT
    );
    CREATE TABLE suppliers (
    supplier_id INT PRIMARY KEY IDENTITY(1,1),
    supplier_name VARCHAR(255) NOT NULL
    );
    CREATE TABLE sales (
    sale_id INT PRIMARY KEY IDENTITY(1,1),
    transaction_date DATE NOT NULL,
    product_id INT,
    amount DECIMAL(10, 2) NOT NULL,
    FOREIGN KEY (product_id) REFERENCES products(product_id)
    );
    INSERT INTO suppliers (supplier_name) VALUES ('TechCorp'), ('MobileMasters'), ('AudioSounds');
    INSERT INTO products (product_name, supplier_id) VALUES
    ('Laptop', 1),
    ('Mobile', 2),
    ('Headphones', 3);
    INSERT INTO sales (transaction_date, product_id, amount) VALUES
    ('2022-12-01', 1, 1200),
    ('2022-12-10', 1, 1300),
    ('2022-12-20', 1, 1100),
    ('2022-12-02', 2, 1500),
    ('2022-12-12', 2, 1600),
    ('2022-12-22', 2, 1400),
    ('2022-12-05', 3, 100),
    ('2022-12-15', 3, 120);
    INSERT INTO sales (transaction_date, product_id, amount) VALUES
    ('2023-01-03', 1, 1230),
    ('2023-01-13', 1, 1280),
    ('2023-01-23', 1, 1190),
    ('2023-01-04', 2, 1520),
    ('2023-01-14', 2, 1670),
    ('2023-01-24', 2, 1460),
    ('2023-01-06', 3, 110),
    ('2023-01-16', 3, 115);
    #Sqlcoding #windowfunction #CTE #commontableexpression #WITHCTE #Having #DateBetween #sqlServer #businessAnalyst #FAANGSQL #AppleInterview #AppleInterviewQuestion #cumulativeSales
    #SQLCUmulative #SQLRANk #DenseRank #SubQuery #QueryOptimization #SqlOptimization
    #SQLTop5 #SQLHighest

Комментарии • 6

  • @vaibhav2347
    @vaibhav2347 9 месяцев назад +1

    Pretty good....

  • @senp4i186
    @senp4i186 9 месяцев назад

    Thank you for the video I'm so new to this and I managed to understand most of it ❤ it is Hella helpful thanks

    • @SidraCodes-LetsGo
      @SidraCodes-LetsGo  9 месяцев назад

      Glad to hear that. In each video, I am providing insert table and records scripts for you to practice. Pls use that so you can benefit. ☺️

    • @senp4i186
      @senp4i186 9 месяцев назад

      @@SidraCodes-LetsGo I have a question if u could answer I would appreciate it forbthe growth with did we go with the positive and not both positive and negative growth

    • @SidraCodes-LetsGo
      @SidraCodes-LetsGo  9 месяцев назад

      It depends what you're looking for .. positive shows sales growth and negative usually means decrease in the growth. If you prefer to show both then you can but it has to be defined otherwise it can be interpreted incorrectly. Hope this helps.

    • @senp4i186
      @senp4i186 9 месяцев назад

      @@SidraCodes-LetsGo yes it did thank you so much