Forum Discussion

Whitewater100's avatar
Whitewater100
Solution Sage
4 years ago
Solved

SQL Code

Hello:   I am looking to see how you would answer these two questions using SQL? Any input is appreciated! Thanks   Customer Name Month & Year Sales Amt A Jan-20 100 B Feb-20 200 ...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Whitewater100,

    As lbendlin said, your requirement seems more related to t-SQL query coding. You can post at the SQL Server forum to get better support.

    In addition, you can also try to use the following follow if it helps. 

    Steps:

    1. Create a select query to search customer names from the raw table.

    2. Add a subquery to search the customer names from the table when the year of date is less than 2021.

    Subqueries (SQL Server) - SQL Server | Microsoft Docs

    3. Use t-SQL 'Not IN' operator to add conditions to the main query to get customers that are not included in the subquery.

    SQL NOT IN Operator (mssqltips.com)

    For example:

    select
        *
    from
        Sales as s
    where
        s.CustomerName not in (
            select
                CustomerName
            from
                Sales
            where
                Year(Sales.Date) < 2021
        )

    Regards,

    Xiaoxin Sheng