Skip to content

Tag: sql

Lead window function in mysql to find sales

Given this table. I would like to know for each day how many different customers made a sale on date t and and t+1. The result for date 2021-06-30 is 2 because customer 1 and 3 made a sale in t and t+1. Answer Use LEAD() window function for each distinct combination of date and customer to create a flag

How do I do nested if statements in SQL?

Write a program that will check the answers for the latest test. The program will be given a table answers with the following columns: id – the unique ID of the question; correct_answer – the correct answer to the question, given as a string; given_answer – the answer given to the question, …

Compare two tables via the three tables SQL

I plan to compare two tables via the three table. my query is as the following if the count is zore, then the tableA and TableC match, otherwise, these two tables do not match It takes a long time to run the query. Do we have a way to compare tableA and tableC fast? Question: How to compare tableA and

Converting string to a date but date not formatted properly

I am having issues with converting a string into a date. The issue is that the format of the string does not easily convert to a date. For example, all the dates are set up like APR-19, or JAN-21. I am not sure how to properly cast this. Here is the SQL I am using. Answer in PostgreSQL it is

Getting values from 3 tables where two of those are self-joined

Problem Introduction: I’m working on a faker e-banking system as a side project for practicing my SQL skills (which are super bad), and I’m now stuck at a point where I want to pull data from two tables but cannot do that with joins So, basically I have a users table which looks like this: And I h…