| Written by Nikos Vaggalis | |||
| Thursday, 19 December 2013 | |||
Page 2 of 2
That’s happening because column m.unit is used in the SELECT clause but not in the GROUP BY clause. This is a perfectly valid and reasonable response from our DBMS, but in this exceptional case, selecting columns without including a non-aggregate column in the group by clause would be handy. But this can’t happen if we are not explicit in what we ask for :
This works because of an inline view (marked in red) which acts as a temporary table holding the value for each row : Result Set 3 Material_id Year Value TX002 1/1/2013 360ドル TX003 1/1/2013 680ドル.01 and exporting material_id and year to the outside scope, both of which will subsequently used for joining with the Accounts table of the outer query ( a.material_id = b.material_id and a.year = b.year), producing : Result Set 4 Account_category Account_id Value 01 220201511 360ドル 01 220201511 680ドル.01 and finally grouped into : Result Set 5 Account_category Account_id Summed_amount 01 220201511 1040ドル.01
Other SQL WorkshopsSQL Workshop - Selecting columns without including a SQL Workshop - Subselects And Join More SQL Workshop soon! Related ArticlesSQL Server: Quickly get row counts for tables, heaps, indexes, and partitions The First Things I Look At On A SQL Server – Part 1 The First Things I Look At On A SQL Server – Part 2 A Generic SQL Server Compression Utility To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter. [画像:SQLW] Comments
or email your comment to: comments@i-programmer.info
Google Releases EmbeddingGemma-State Of The Art On-Device Embedding 02/10/2025 Google has released a small, specialized, but powerful model that can run on low resource devices. DH2i Launches DxEnterprise For SQL Server 2025 21/10/2025 DH2i has released DxEnterprise for SQL Server 2025 which brings mission-critical high availability capability for SQL Server 2025-backed AI applications. More News
<< Prev - Next |
|||
| Last Updated ( Thursday, 06 September 2018 ) |
SQL Workshop - Selecting columns without a non-aggregate column