Note that there are some explanatory texts on larger screens.

plurals
  1. POVery hard greatest n per group query
    primarykey
    data
    text
    <p>I have a very complexe query here, I try to give you an overview about the necessary tables here:</p> <ul> <li>RPG</li> <li>RPGCharacter</li> <li>RPGPost</li> <li>User</li> </ul> <p>We have X Chars per RPG, x Posts per Char. 1 User can have X Chars, but 1 Char only depens on 1 User.</p> <p>What I want is a query in which I got the last post per RPG within information about the Username who wrote this, the character and the RPG itself addition to a number how much RPGPosts per RPG we have (total).</p> <p>This is how far I solved it until now:</p> <pre><code> SELECT c.RPGID, c.Name, DateTime, r.Name, u.Username, t.count FROM dbo.RPGCharacter c inner join ( SELECT CharacterID, MAX(DateTime) MaxDate FROM RPGPost GROUP BY CharacterID ) MaxDates ON c.RPGCharacterID = MaxDates.CharacterID INNER JOIN RPGPost p ON MaxDates.CharacterID = p.CharacterID AND MaxDates.MaxDate = p.DateTime Inner join RPG r on c.RPGID = r.RPGID Inner join [User] u on u.UserID = c.OwnerID inner join (Select RPG.RPGID, Count(*) as Count from RPGPost inner join RPGCharacter on RPGPost.CharacterID = RPGCharacter.RPGCharacterID inner join RPG on RPG.RPGID = RPGCharacter.RPGID where RPGPost.IsDeleted = 0 Group by RPG.RPGID) t on r.RPGID = t.RPGID Order by DateTime desc </code></pre> <p>Result : <a href="http://abload.de/image.php?img=16iudw.jpg" rel="nofollow">http://abload.de/image.php?img=16iudw.jpg</a></p> <p>This query gives me all I want but has an Errors:</p> <p>1) It gives me the last post per Character, but I need the last Post per RPG</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