You must Sign In to post a response.
  • Category: SQL Server

    Find recurred records in a table

    I have a table for orders:

    id date amount
    ------------------------
    101 01/10/2018 1000
    102 04/10/2018 2000
    103 15/10/2018 500
    104 25/10/2018 6000
    105 28/10/2018 100
    106 04/11/2018 2000
    107 15/11/2018 500
    108 28/11/2018 100
    109 29/11/2018 200
    110 30/11/2018 100

    I need result like below:

    id date amount
    --------------------------
    102 04/10/2018 2000
    103 15/10/2018 500
    105 28/10/2018 100


    i need only those rows which are recurred in next month and have same amount value and DD part of the date.
  • #769832
    i can not give you the sql statement but I can give you the steps that will help you to write the query
    1. Write a query to get the amount of all records of next month.
    Select amount from table where month(28/11/2018)=11
    2. Now select all the records of current month where any record amount equal to the output of Step 1 like
    Select * from table where amount exist (Select amount from table where month(28/11/2018)=11) and month = current month.
    hope you will get the desire output


  • Sign In to post your comments