How to SQL join tables, selecting the largest value in Access-VBA Function?

前端 未结 2 1603
青春惊慌失措
青春惊慌失措 2021-01-27 19:16

I currently have the following Access VBA function, which operates as explained in a previous question (very useful for understanding this question):

Private Fun         


        
2条回答
  •  清酒与你
    2021-01-27 19:55

    I would consider creating a reference table with value field as it easier to maintain specially when the values change overtime.

    CREATE TABLE tblReference (field_txt text, val Integer);

    Get the field_txt with highest value and unique field then left join(inner join) to your current dataset.

    qry_field3_max = "SELECT [Field3],[commonField] FROM tblReference INNER JOIN (SELECT [commonField], MAX(val) as val FROM tblReference INNER JOIN tblNameTemp on tblReference.[field_txt]=tblNameTemp.[Field3] Group By [commonField]) as tbl_max_fields on tblReference.val=tbl_max_fields.val"

提交回复
热议问题