count and max from a table

  • Hi ,

    I am looking for a query to find count and max values from a table .

    Please see attachment.

    Any suggestions pls.

     

    Thank you !

    Attachments:
    You must be logged in to view attached files.
  • Should be a very basic query. Try

    SELECT Object_Id, Schema_Name, Table_Name, SUM(Value1) AS Value1, MAX(Date1) AS Date1
    FROM Table
    GROUP BY Object_Id, Schema_Name, Table_Name
    ORDER BY Object_Id, Schema_Name, Table_Name
  • Thank you

    • This reply was modified 1 year, 9 months ago by  adisql.
  • I would like to update Table2 with Table select statement results .But somehow it is not working.

    update Tabl2 set Value1,Date1

    SELECT Object_Id, Schema_Name, Table_Name, SUM(cast(Value1 as bigint)) AS Value1, MAX(Date1) AS Date1

    FROM Table

    GROUP BY Object_Id, Schema_Name, Table_Name

    where Table.Object_id = Table2.object_id

    • This reply was modified 1 year, 9 months ago by  adisql.
  • Does this do what you need?

    UPDATE a
    SET a.Value1 = b.Value1,
    a.Date1 = b.Date1
    FROM Table2 AS a
    JOIN (
    SELECT Object_Id,
    SUM(cast(Value1 as bigint)) AS Value1,
    MAX(Date1) AS Date1
    FROM Table1
    GROUP BY Object_Id
    ) AS b ON a.Object_id = b.Object_id

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply