![]() ![]() I want to use a select AS statement to select multiple columns. (Although it may make sense to create a view for a particular set of pivoted columns if that information is requested often or used in many other queries – makes those queries simpler and more maintainable.) Also, as you can see, pivoting can be done as a single step operation – no need to derive a set of CASEs first and only then aggregate them. Select Multiple columns AS statement Home Programming Forum Databases Forum Discussion / Question mrhankey 0 Junior Poster in Training 12 Years Ago Hi, I have tried to Google this but cant find anything. Meta_key IN ('first_name','last_name','street_add','city','state')įundamentally, this is the same approach as the one suggested by SQLHound, except, in my opinion, there is no need to create a view specifically to solve this problem. ![]() mysql> Drop table Bird Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE. MAX(CASE meta_key WHEN 'state' THEN meta_value END) AS state Sort on multiple columns : Sort Order Select Clause SQL / MySQL. MAX(CASE meta_key WHEN 'city' THEN meta_value END) AS city, MAX(CASE meta_key WHEN 'street_add' THEN meta_value END) AS street_add, MAX(CASE meta_key WHEN 'last_name' THEN meta_value END) AS last_name, MAX(CASE meta_key WHEN 'first_name' THEN meta_value END) AS first_name, MySQL does not have it, but there is a universal method that works in most products, including MySQL: conditional aggregation. Some SQL products have dedicated syntax for this operation. ![]() The ORDER BY clause sorts rows using columns or. You essentially want to pivot the meta_value column. In case you want to sort the result set by multiple columns, you use a comma (,) to separate two columns. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |