Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>1) It might not be so easy. MS SQL Server can <code>PIVOT</code> a table on an axis, but dumping the resultset to an array and sorting there (assuming this is tied to some sort of program) might be the simpler way right now if you're new to SQL.</p> <p>If you can manage to do it in SQL it still won't be enough info to create a new table, just return the data you'd use to fill it in, so some sort of external manipulation will probably be required. But you can probably just use <code>INSERT INTO [new table] SELECT [...]</code> to fill that new table from your select query, at least.</p> <p>2) You can join on <code>attributes</code> for each unique attribute:</p> <pre><code>SELECT [...] FROM data AS d JOIN persons AS p ON d.person_id = p.person_id JOIN attributes AS weight ON p.attribute_id = weight.attribute_id HAVING weight.attribute_type = 'Weight' JOIN attributes AS height ON p.attribute_id = height.attribute_id HAVING height.attribute_type = 'Height' [...] </code></pre> <p>(The way you're joining in the original query is just shorthand for <code>[INNER] JOIN .. ON</code>, same thing except you'll need the <code>HAVING</code> clause in there)</p> <p>3) It depends on the type of <code>JOIN</code> you use to match parent/child relationships, and any dates you're filtering on in the <code>WHERE</code>, if I'm reading that right (entirely possible I'm not). I'm not sure quite what you're looking for, or what kind of database you're using, so no good answer. If you're new enough to SQL that you don't know the different kinds of <code>JOIN</code>s and what they can do, it's very worthwhile to <a href="http://en.wikipedia.org/wiki/Join_%28SQL%29" rel="nofollow noreferrer">learn them</a> - they put the R in RDBMS.</p>
 

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