Search code examples
sqlcase

How to match a Column from a calculation column (non-existing) within the same table


Well, I have to match the values from the column 'TotalAmount' with the calculation of two columns (UnitPrice and Quantity)

My guess is that I need to use Case statement but I don't know where to locate the multiplication.

Also, maybe I should create another column within the same table with the results of the multiplication and then do the matching?

Here is the table: enter image description here

Thanks in advance


Solution

  • WITH T AS ( SELECT (quantity*unitprice) as total 
                  FROM tb1 ) 
    (SELECT * 
       FROM T 
      INNER JOIN tb1 ON tb1.totalAmount=T.total
    ) 
    

    Below are the screenshots Data

    Output