Skip to content

Tag: sql

Presto SQL date_format extract week of year

Documentation : https://prestodb.io/docs/current/functions/datetime.html I have epoch timestamps from which I want to extract week of the year like 2021-32, 2020-50, 2021-02 and so on. However I am getting up some wrong values like : week = 2021-53 for Epoch-Time corresponding to Jan 1, 2021 or Jan 2, 2021. I…

SQL Merge Into with multiple statements

I’m trying to keep a historic table of another one. When updating the original I would like to insert rows into the historic one. I’m using Sql Merge: Can I make multiple statements in the same “when” condition?, as such: Answer Normally you can INSERT only into one table. The syntax d…

Can I combine more than one function in a single line in SQL?

What I want to do is simply to use more than 1 function in a single query. I’m new to SQL so I’m sorry if I’m getting some words wrong. select cognom from emp where length(cognom) = 10, replace(cognom, ‘ ‘, ‘*’); Answer Yes, you can, as long as you respect the syntax.…

Search SQL database with multiple filters

I have the following code: This gives me the rows where “category_id” is equal to the 1. I now want the SELECT statement to return rows where the “category_id” is equal to one of the values I give it. So a simple SELECT statement would look something like this The problem is that I wou…

SQL query for last 365 days report

I have a reports table with the following structure : I want a SQL Query to get the report for the last 365 days by following conditions : Group dates if the same date is repeated. The days which the report is not available for the last 365 days, I need those days added to the result rows with 0