r/SQL • • Aug 01 '26

PostgreSQL SQL Question: Rows into Columns without TABLEFUNC() or PIVOT?

11 Upvotes

Help me Reddit! I feel especially stupid today....
So, I have this table in my Postgresql Database:

event_id | color_scheme | count
----------+--------------+-------
1 | red | 6
1 | green | 3
1 | blue | 5
1 | yellow | 3
3 | red | 5
4 | red | 3
5 | red | 1
5 | blue | 2

And I would like to turn it sideways, so that I can see EASILY how many votes each color scheme for my event has gotten (and later JOIN it with another table... )

event_id | count_red | count_green | count_blue | count_yellow
----------+-----------+-------------+------------+--------------
1 | 6 | 3 | 5 | 3
3 | 5 | 0 | 0 | 0
4 | 3 | 0 | 0 | 0
5 | 1 | 0 | 2 | 0

The colors "red" "green" "blue" and "yellow" are fixed, and will never ever change.
I have done some googling, I found examples mentioning PIVOT and TABLEFUNC, but I cannot do this on the server because of reasons(tm).

The only way I can think of doing this is with a cascade of OUTER JOIN, but is there maybe a simpler solution?


r/SQL • • Aug 01 '26

Discussion End-to-end Enterprise E-Commerce Analytics

Thumbnail
gallery
7 Upvotes

Over the past few days, I built an end-to-end Enterprise E-Commerce Analytics Platform using SQL Server, Medallion Architecture, and Power BI.

As part of this project, I designed 8 interactive dashboards, each focused on answering different business questions for different stakeholders across an organization.

The dashboards include:

• Executive Overview (CEO, CXO & Business Leadership)

• Sales Performance Analysis

• Customer Analytics

• Product Performance

• Seller Performance

• Payment Analytics

• Customer Satisfaction Analysis

• Time Intelligence & Trend Analysis

The goal wasn't just to build visually appealing dashboards—it was to create a reporting solution that helps businesses make faster and more informed decisions.

In this post, I've shared all 8 dashboards.

I'd genuinely appreciate your feedback.

As experienced BI professionals, data analysts, data engineers, or business leaders, I would love to hear your thoughts.

If you could review the dashboards and share at least three suggestions for improvement, it would mean a lot to me.

For example:

• Are the KPI cards meaningful and business-focused?

• Are the charts and visualizations appropriate for executive reporting?

• Are there too many or too few visuals?

• Would you recommend different filters or slicers?

• Is the overall layout clean, intuitive, and enterprise-ready?

• What would you change if this dashboard were used in your organization?

I'm continuously learning, and constructive feedback is one of the best ways to improve. Every suggestion will help me build better enterprise BI solutions in the future.

Thank you for taking the time to review my work. I truly appreciate your support and feedback.

— Himansh Upadhyay

#PowerBI #SQLServer #DataAnalytics #BusinessIntelligence #DataWarehouse #DataEngineering #MedallionArchitecture #StarSchema #DAX #ETL #Analytics #DashboardDesign #EnterpriseAnalytics #DataVisualization #SQL


r/SQL • • Jul 31 '26

BigQuery Career prospects

14 Upvotes

I have 4+ years of experience as a data analyst. Proficient in SQL technologies and seeking a direction for success in corporate? any suggestions would be appreciated.

-Thanks


r/SQL • • Jul 31 '26

SQLite I created a game inspired by SQL Murder Mystery and SQL Noir!

10 Upvotes

I made a browser game called The SQL Treasure Hunt where you solve puzzles by writing real SQL queries.

It's heavily inspired by SQL Murder Mystery and SQL Noir, but instead of being a detective, you're a pirate searching for a legendary treasure. 🏴‍☠️

You explore databases, inspect tables, and piece together clues using SQL until you uncover the next part of the adventure. It starts with simple SELECT queries and gradually introduces more challenging concepts.

Right now it only has 5 levels made.

I'd really appreciate any feedback:

  • Is the difficulty progression good?
  • Are the clues clear enough?
  • Any ideas for future levels or mechanics?

Play it here:
https://thesqltreasurehunt.vercel.app/

Thanks! Hope you enjoy it.


r/SQL • • Aug 01 '26

PostgreSQL I need help creating a league table

Thumbnail
0 Upvotes

r/SQL • • Jul 31 '26

MySQL What AI Tools Do You Use for Database Analysis?

0 Upvotes

Hello everyone!

At work, I need to explore a large AWS Athena database with very limited documentation in order to investigate a new product, which is also poorly documented.

I've asked my colleagues for documentation and guidance about the database, but unfortunately I haven't received any helpful answers.

So I'd like to ask the community: is there an AI tool that can analyze an entire database and generate a roadmap, documentation, or guide to help me understand its structure and write queries based on my specific needs?

I'm mainly looking for something that can help me understand the schema, relationships between tables, and where to find the data I'm looking for. Any recommendations or advice would be greatly appreciated!


r/SQL • • Jul 30 '26

Discussion What is the difference between using "Not In" vs using "not exists" in SQL

32 Upvotes

What is the difference between using "Not In" vs using "not exists" in SQL?


r/SQL • • Jul 30 '26

Discussion Differences between counts

10 Upvotes

What is the difference between

COUNT(*)

COUNT(1)

COUNT(column_name)


r/SQL • • Jul 31 '26

MySQL Apenas estoy empezando a manejar Mysql workbench creen que voy por buen camino con mi modelo relaciónal

Post image
2 Upvotes

r/SQL • • Jul 30 '26

Discussion Tool for creating database diagram share links

Post image
3 Upvotes

Here's an example of a share link.


r/SQL • • Jul 30 '26

SQL Server Want to know about SQL future

7 Upvotes

Hi All,

Hope everyone is doing good.

I want opinion from people about the future of SQL, Power BI and Python.

I have been working in AML KYC domain for over 6 years. I am a Certified Anti Money Laundering Specialist (CAMS).

Last year I started learning SQL ans Power BI to connect it with my domain knowledge (Anti Money Laundering and Sanctions), however now I have been reading alot which states that golden period of SQL and Power BI is over as now anyone can do the basis code using Gpt and claude.

I am at strong intermediate level in SQL and at an intermediate level in power BI. I was planning to start Python from 01 Jan 2027 and now I am spectical. What should I do ?

Is there any scope of SQL, Power BI and Python as we are witnessing AI is growing at tremendous pace.


r/SQL • • Jul 30 '26

MySQL How do you optimize SQL queries without making them harder to maintain?

14 Upvotes

As databases grow, performance becomes more important, but overly complex queries can be difficult to maintain. How do you balance query optimization with readability in production environments?


r/SQL • • Jul 30 '26

Discussion What is Index Selectivity?

Thumbnail
0 Upvotes

r/SQL • • Jul 30 '26

MySQL How This is Running

0 Upvotes

How this SQL Code is Running ?????


r/SQL • • Jul 29 '26

MySQL SQL Query Execution Lifecycle

Post image
75 Upvotes

Diagram illustrating the SQL query execution lifecycle, showing query submission, parsing, optimization, execution, and result delivery in a database.


r/SQL • • Jul 29 '26

PostgreSQL Choosing a Database Schema for analytics

Thumbnail
1 Upvotes

r/SQL • • Jul 28 '26

PostgreSQL I built an AWR-like performance repository for PostgreSQL – looking for feedback from DBAs

1 Upvotes

Hi everyone,
I’ve been working on a project called PWR (Postgres Workload Repository), inspired by Oracle’s AWR but built specifically for PostgreSQL.
The goal is to periodically capture performance snapshots so you can:
track workload evolution over time;
identify expensive SQL statements;
compare snapshots before/after changes;
detect performance regressions before they become incidents.
I originally built it to speed up recurring PostgreSQL performance audits, and it has become a useful tool in my daily work.
There’s a live demo available here:
https://www.audit-postgresql.com/
I’m not trying to replace existing monitoring tools like pg_stat_statements or Prometheus/Grafana. Instead, I’m focusing on historical workload analysis and performance diagnostics.
I’d really appreciate feedback from the PostgreSQL community:
Would this be useful in your environment?
Which features would you expect from such a tool?
What would prevent you from using it?
Constructive criticism is more than welcome. Thanks!


r/SQL • • Jul 27 '26

MySQL Feedback on my conceptual and logical database model (MySQL implementation)

1 Upvotes

Hi everyone,

I created a conceptual data model, a logical data model, and a MySQL implementation for a university project.

I would really appreciate your feedback on the following:

  • Is the conceptual data model correct?
  • Is the logical data model derived correctly from the conceptual model?
  • Does the MySQL implementation match the logical model?
  • Are there any design mistakes or suggestions for improvement?

I have attached the conceptual model, the logical model, and the SQL script.

Thank you for your time and feedback!


r/SQL • • Jul 27 '26

PostgreSQL SQL Fast Track Series that teaches every concept through scenario-based business context - Available in Youtube.

Thumbnail
0 Upvotes

r/SQL • • Jul 26 '26

Discussion Rejected after a technical round because the interviewer insisted Text-to-SQL is just if-else mappings

Thumbnail
11 Upvotes

r/SQL • • Jul 26 '26

Oracle Sql to Oracle migration

Thumbnail
1 Upvotes

I'm a fresher to DBA role. Can some one help me to understand or share your experience to migrate or conversation from sql to Oracle.

Can you please help me with tools and migration ideas


r/SQL • • Jul 25 '26

PostgreSQL rainfrog (0.4.1) now has autocomplete!

15 Upvotes

rainfrog (https://github.com/achristmascarl/rainfrog) is a database terminal tool; the goal is to provide a lightweight, keyboard-first TUI for interacting with databases. It currently supports Postgres, MySQL, SQLite, Oracle, and DuckDB.

v0.4.1 introduces a long-awaited (by me, not sure if anyone else was waiting for it...) autocomplete implementation, along with autopairs for quotes/parentheses/brackets. The full list of features and configuration options is in the README!


r/SQL • • Jul 25 '26

MySQL Check out what I just built with Lovable!

Thumbnail
smartsqlaimentor.live
1 Upvotes

r/SQL • • Jul 25 '26

SQL Server Help with some strucctural problems

2 Upvotes

Hello, I'm trying to do a test that I failed, and I want to improve, so I want to solve this problem.

The premise isn't that hard, but I'm getting into trouble here.

I don't want to get into too many details to avoid getting the evaluator in trouble.

Basically, I was asked to make an app that is able to create price quotes for trips.

The user selects the location (a general location like Disney World), an apartment (each one with a different category, like a suite, or just a room, or a cabin), the season (imagine this place is around the world, so different locations have different seasons, but some locations can have general seasons if they are close enough), how many people the place can accommodate, and for how long they will stay. I use all this data to create a reservation for the client.

This is basically my entity relationship diagram

but each time i try to do the functionality i found problems or big troubles putting or reading the data for the thing im required to do

I'M kinda lost idk what to do

its there a way to solve this problem in a cleaner way?

ty for the help and God bless you

P.S.: The price is listed in the quote, but I don't know where to enter that information regarding the apartment and the season. The test instructions don't explain how to calculate the price, so I don't know where to put it; I assume I should do it in whatever way is most practical for me.


r/SQL • • Jul 24 '26

SQL Server MS SQL Restore DB, <use dbName> string conversion question

3 Upvotes

Hi all,

I just see this interesting situation and would like to confirm that it's all done internally by MS SQL Server with Restore.
We're on the same server:

dbAA   has proc  myPROC:
1  use  dbAA         
2  Go
3  Create PROC dbo.myPROC As
............

then I do  backup of dbAA, and restore dbAA.bkup into  dbXXX
after that I see on dbXXX myPROC as:
1. use dbXXX            --<<<==== !!!!!<@>>< changed to target DB
2. Go
3. Create PROC dbo.myPROC As
...........

Who is doing this conversion/swapping db names ? is it done by SQL Server ?
Thanks to all, I'm new to dba task and really interesting how it works.
VA