Member-only story
Pivot query in MySQL — Learning by example.
While reading in a fantastic SQL book I frequent quite a bit, I discovered a type of query in one of the examples that I really should know. For a better learning experience, in order to solidly the concepts presented, I applied them to some data that I am familiar with. The topic: pivoting rows of data. Although I am aware of this data presentation, I have never studied a pivot query. ‘So why not learn it then’ I thought to myself. Are you interested in learning about a pivot query also? Continue reading and see an easy-to-comprehend example…
OS and DB used:
- OpenSuse Leap 15.1
- MySQL 8.0.20
Self-Promotion:
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!
To start, we will visit this CREATE VIEW
statement, which forms the base data used in this post:
MySQL localhost:33060+ ssl walking SQL > CREATE VIEW vw_hot_hikes AS
-> SELECT day_walked, cal_burned
-> FROM walking_stats
-> WHERE MONTHNAME(day_walked) IN (‘June’,’July’,’August’);
Below, is a more detailed output using the SHOW
command: