Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Group By Problem
    primarykey
    data
    text
    <p>I have a table that has 3 cols namely points, project_id and creation_date. every time points are assigned a new record has been made, for example.</p> <pre><code>points = 20 project_id = 441 creation_date = 04/02/2011 -&gt; Is one record points = 10 project_id = 600 creation_date = 04/02/2011 -&gt; Is another record points = 5 project_id = 441 creation_dae = 06/02/2011 -&gt; Is final record </code></pre> <p>(creation_date is the date on which record is entered and it is achieved by setting the default value to GETDATE())</p> <p>now the problem is I want to get MAX points grouped by project_id but I also want creation_date to appear with it so I can use it for another purpose, if creation date is repeating its ok and I cannot group by creation_date because if I do so it will skip the points of project with id 600 and its wrong because id 600 is a different project and its only max points are 10 so it should be listed and its only possible if I do the grouping using project_id but then how should I also list creation_date</p> <p>So far I am using this query to get MAX points of each project</p> <p>SELECT MAX(points) AS points, project_id <br> FROM LogiCpsLogs AS LCL <br> WHERE (writer_id = @writer_id) AND (DATENAME(mm, GETDATE()) = DATENAME(mm, creation_date)) AND (points &lt;> 0) <br> GROUP BY project_id <br> </p> <p>writer_id is the ID of writer whose points I want to see, like writer_id = 1, 2 or 3.</p> <p>This query brings the result of current month only but I would like to list creation_date as well. Please help.</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.
 

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