SQL - pivot three rows into three columns with static column names?
<p>I'm relatively new to SQL, but I have a query,</p>

<pre><code>select top 3 LoginDateTime from UserLogins where Username = 'John Doe' order by LoginDateTime desc
</code></pre>

<p>That returns the three most recent logins.</p>

<p>How would I go about pivoting the query so that I end up with a result where each date is in its own column, and where the column headers are '1st', '2nd', and '3rd'?</p>

<p>Thanks!</p>

<p>ADDENDUM: The query is running on MS SQL Server targetting specifically the content of the result (which may change in future to include more than just the top three logins).  It could even become a case where the column titles themselves have to change over time, so static titles (as opposed to programmatically generated) would be the ideal solution.</p>