Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should apply grouping. Something like</p> <pre><code>SELECT LastName, SUM(NetPaidAmount) AS TotalPaid FROM XYZ GROUP BY LastName </code></pre> <p>The exact grouping may differ according to the columns you want to output.</p> <p><strong>Update:</strong></p> <p>If you groupy additionally by Code1, then the sum actually sums all NetPaidAmount where Lastname together with Code1 is unique. If you want to have the maximum additionally to another grouping level you must combine two queries. One with your groping and one that groupy only over lastname.</p> <p>Not tested, written out of my head:</p> <pre><code>SELECT A.Lastname, A.TotalPaid, B.Code1 FROM ( SELECT LastName, SUM(NetPaidAmount) AS TotalPaid FROM XYZ GROUP BY LastName ) A INNER JOIN ( SELECT Lastname, Code1 FROM XYZ GROUP BY Lastname, Code1 ) B ON B.Lastname = A.Lastname </code></pre> <p>My SQL is T-SQL flavor as I'm used to query against Microsft SQL Server, and this is most likely not the fastest was to do such things. So based on what DB you are using, the SQL might look different.</p> <p><strong>Update 2:</strong></p> <p>( I had to reformat you desired output to understand more, you can use code sections to output tables as they respect spaces )</p> <p>I do not see the need for NetPaidAmount for the desired output. The desired output should be produced with something like this ( based on the evidence you provided ):</p> <pre><code>SELECT Lastname, MAX ( Code1 ) As Code1 FROM XYZ GROUP BY Lastname </code></pre> <p>More details are not visible from your question and you should provide more information to get more help on which direction</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload