Skip to content

cte FULL OUTER JOIN MYSQL

I have this table(called trial): ‘year1’ refers to values in Column ‘val1’, ‘year2’ to values in Column ‘val2’. I want to get totals of all values grouped by year. So I would like to see a result like: I set up a common table expression(cte) using a self join to…

how to get the 1st day of the year sql query oracle

I need a sql query to get a 1st day of the 1st month of the year which i am passing. ex: If i am passing 2021, my output should be 01-JAN-2021 If i am passing 2020, my output should be 01-JAN-2020 Answer Assuming you are passing the year as the bind variable :year then: or

Order by the Compute of Count in SQL

Hi I get the results that I’m looking for however, I want to order it by the count from the compute. Anyone have any ideas. Answer One approach is to use window functions to calculate and order by that value. The following orders the result by n descending, but doesn’t include n in the final SELEC…

SQL consolidate overlapping dates based on criteria

I’m trying to merge overlapping dates between Admit and discharge dates of patients. There are a few edge cases which I couldn’t cover in the query. Input Expected Output Query I used the logic that was here But this doesn’t cover the edge case for ID 2 and 3. Also the subquery is slower whe…

How to parse a Clickhouse-SQL statement using ANTRL4?

Objective : Add an additional WHERE clause to any given Clickhouse statement. I’m using the following Antlr grammars to generate Java classes for a lexer & parser. Lexer grammar https://github.com/ClickHouse/ClickHouse/blob/master/utils/antlr/ClickHouseLexer.g4 Parser grammar https://github.com/Clic…

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