Home Forums SQL Server 2008 T-SQL (SS2K8) Find Min of the Two columns when multiplied and Grouped RE: Find Min of the Two columns when multiplied and Grouped

  • Hi Varun,

    please go through this code. i hope this helps you to get the answers..

    SELECT a3.*

    FROM (SELECT a.GroupID, MIN(MULTICOLUMN)MULTICOLUMN

    FROM (SELECT ID, [FIRST] * SEC MULTICOLUMN, GROUPID FROM SAMPLE_TEST)a

    JOIN SAMPLE_TEST b On a.ID = b.ID

    GROUP BY a.GroupID

    ) a1

    JOIN (SELECT ID, [FIRST] * SEC MULTICOLUMN, GROUPID FROM SAMPLE_TEST) a2 On a1.GroupID = a2.GroupID AND a1.MULTICOLUMN = a2.MULTICOLUMN

    JOIN SAMPLE_TEST a3 On a2.ID = a3.ID

    Ini your sample, for the ID value 1 & 3 belongs to same groupID "16" and the multiple for Column first&sec is same. so you would be getting 2 rows for the same groupID 16.

    If the query has to be changed bit, let me know i can help you in getting the result.

    All the best,

    Vijay Vasudevan