ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025

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

  • @ksahiti1227
    @ksahiti1227 3 месяца назад

    Thanks

    • @ksahiti1227
      @ksahiti1227 3 месяца назад +1

      Your content is too good. All the interviews which I attended got these questions sir. I cracked interview by watching your videos☺ Please take this amount as my token of appreciation.

  • @user-gq6cg3ls7f
    @user-gq6cg3ls7f 4 месяца назад +2

    another approach
    with cte as(
    select *,
    count(*) over (partition by category order by productID desc) RN
    from Products_Thus
    ),
    cte2 as(
    select *,
    ROW_NUMBER() over (partition by category order by productID) RN
    from Products_Thus
    )
    select c2.ProductID, c.Product, c.Category from cte c inner join cte2 c2
    on c.RN=c2.RN
    and c.Category=c2.Category
    order by c2.ProductID

  • @DarnasiChakravarthy
    @DarnasiChakravarthy 4 месяца назад +1

    You are content is too good

  • @mychoice7126
    @mychoice7126 23 дня назад

    Create table bdrproducts (
    Product_Id int primary key,
    Product_Name varchar(15),
    Product_Type varchar(15)
    );
    Insert into bdrproducts values(1,'Laptop','Electranics')
    Insert into bdrproducts values(2,'SmartPhone','Electranics')
    Insert into bdrproducts values(3,'Tablet','Electranics')
    Insert into bdrproducts values(4,'Headphone','Accessories')
    Insert into bdrproducts values(5,'Smartwatch','Accessories')
    Insert into bdrproducts values(6,'Keyboard','Accessories')
    Insert into bdrproducts values(7,'Mouse','Accessories')
    Insert into bdrproducts values(8,'Monitor','Accessories')
    Insert into bdrproducts values(9,'Printer','Electranics');

  • @pavanakumarpk2525
    @pavanakumarpk2525 4 месяца назад

    Have the habit of keeping the table creation and schema details

    • @datasculptor2895
      @datasculptor2895  4 месяца назад

      Sure sir. Any other suggestions sir? By the way it is already in description

    • @pavanakumarpk2525
      @pavanakumarpk2525 4 месяца назад

      If u keep the copied details directly in the description, there won't be any redirects to other

  • @tanujreddy8597
    @tanujreddy8597 4 месяца назад

    for how much experience this question can be asked

  • @rohitsinghbisht1101
    @rohitsinghbisht1101 4 месяца назад

    Your content is good... please if you can guide so i have cmpleted and understood all type of statement so now how to improve? wether i solve situation based queries + Project or just focus on projects only /? i need gudance as i am thinking about switching to data analytics role

    • @datasculptor2895
      @datasculptor2895  4 месяца назад +1

      Hi..
      If you have covered all topics theoretically, I suggest you practice a lot of questions. This will improve your skills. Once you are confident on solving a sql question, then work on some projects

    • @rohitsinghbisht1101
      @rohitsinghbisht1101 4 месяца назад

      @@datasculptor2895 thanks.. But how good do I have to become? I mean becz there will always be hard questions and how to find some ...

    • @datasculptor2895
      @datasculptor2895  4 месяца назад

      @@rohitsinghbisht1101 you start with easy questions. Learning is a never ending process. You become strong only with experience

  • @sandydalhousie
    @sandydalhousie 4 месяца назад +1

    Another approach here as well:
    with cte as
    (select ProductID, Product, Category,
    ROW_NUMBER() over(partition by Category order by ProductID) as rnk
    from products1),
    cte2 as
    (select ProductID, Product, Category,
    ROW_NUMBER() over(partition by Category order by ProductID desc) as rnk1
    from products1),
    cte3 as
    (select cte.ProductID, cte2.Product, cte.Category
    from cte
    join cte2
    on cte.rnk=cte2.rnk1 and cte.Category=cte2.Category)
    select *
    from cte3
    order by ProductID;

  • @Iamthebestthing
    @Iamthebestthing 4 месяца назад +1

    Order by 1 means I don't know about this
    Explain me order by 1 or order by 2 means

    • @datasculptor2895
      @datasculptor2895  4 месяца назад +1

      Order by 1 means sorting the first column that is present in the select statement. Order by 2 means sorting the second column that is present in the select statement.

    • @Iamthebestthing
      @Iamthebestthing 4 месяца назад

      @@datasculptor2895 i try applying 1 and 2

    • @datasculptor2895
      @datasculptor2895  4 месяца назад +1

      Order by 1,2

  • @HARSHRAJ-gp6ve
    @HARSHRAJ-gp6ve 3 месяца назад

    with cte as(
    select Products.*,ROW_NUMBER()OVER(PARTITION BY Category ORDER BY ProductID) as x1 FROM Products
    ),cte1 as(
    select ProductID as id1,Product as product1,Category as category1,ROW_NUMBER()OVER
    (PARTITION BY Category ORDER BY ProductID DESC) as x2 FROM Products
    ),cte2 as(
    select * FROM cte JOIN cte1 ON cte.x1=cte1.x2 and Category=category1
    )
    select cte2.ProductID,product1,cte2.Category FROM cte2 JOIN Products ON cte2.ProductID=Products.ProductID;

  • @tanujreddy8597
    @tanujreddy8597 4 месяца назад

    SELECT
    productid,
    productname,
    productcategory
    FROM
    (
    SELECT
    ROWNUM r,
    productid
    FROM
    (
    SELECT
    productid
    FROM
    product
    ORDER BY
    product.productcategory,
    product.productid DESC
    )
    ) a,
    (
    SELECT
    ROWNUM r,
    productname,
    productcategory
    FROM
    (
    SELECT
    productname,
    productcategory
    FROM
    product
    ORDER BY
    product.productcategory,
    product.productid
    )
    ) b
    WHERE
    a.r = b.r ORDER BY PRODUCTID;

  • @harshitsalecha221
    @harshitsalecha221 4 месяца назад

    WITH cte1 AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY category ORDER BY category, Productid DESC) as rn,
    ROW_NUMBER() OVER(PARTITION BY category ORDER BY category, Productid) as rn1
    FROM products)
    SELECT c2.productid,c1.product,c1.category FROM cte1 c1
    INNER JOIN cte1 as c2
    ON c1.category=c2.category AND c1.rn=c2.rn1
    ORDER BY c2.productid;