Skip to content

Tag: sql

Pivoting but handling Column Names

I’m currently getting a result-set back as follows: What I’m trying to do is get the results to appear as follows: I’ve put together the following query, and I was curious as to whether someone had a better way of doing it: Here’s the sample data: Answer You can use conditional aggrega…

SQLite Sum over children in self-referencing table

I have a ecosystems table, which is self-referencing because each ecosystem can have sub-ecosystems. Each ecosystem can also have a score (which represents how healthy the ecosystem is). The columns are (with example data): The full_slug column represents the full path from top-level ecosystem down. It is red…

New to SQL and having issues with Sytnax (VB.NET)

I am fairly new to SQL and databases in general (in an intro class in college right now) and I have run into a little snag. I am building a paid time off tracker for people in my department (they are like children and can’t keep track of their own things with the tools we already have). I currently have

SQL find the 2 highest score for each country

I have two tables: maps_query and map_time like below: The question is to find the 2 highest score for each country. Desired output is like below: I was trying to use row_number() over but don’t know how to complete the query. Answer This can be achieved by rank() instead of row_number(). A good referen…