Skip to content

Tag: sql

How to generate multiple combinations from tables using SQL?

I have few combinations of records in my table but i want to generate Multiple combinations from original table. Records in table codeset codevalue column system test1 1 null sys1 test2 2 col2 sys1 test3 3 col3 sys1 test3 4 col4 sys1 test3 5 col5 sys1 test4 null col6 sys1 test5 6 col7 sys2 test5 7 col8 sys2 A…

Can a Wildcard Search Be Performed Amongst Fields

Always grateful for the infinite wisdom from everyone on this site. I deal with some massive databases that are often difficult to search in. One of which is a lead database with over 1.4k columns and 3 million records. Sometimes, I just want to query to see if a certain value exists anywhere in the database …

Presto lag dates, group/partitioned by id

Say that I want to find every time that a client updated their budget. Here’s what my data looks like And the code I’ve run. What I’m expecting returned will be Hence there are NULL values for dt_2 in the first entry of each client_id. I’m not sure what code will accomplish this effect…

SQL: SUM on Aggregate columns

I have this query: Which has this result: However, I’d like to add order_total and item_total in order to get just total. So I’d expect this: Doing this did not work: Another monkeywrench is that the type of the numbers is money not integer. Anyone would be able to help? Answer If any of the 2 sum…

Adding hours to dates in Presto

In a Presto db table, I have two string fields, a date of the form, ‘2022-01-01’, and an hour of the form, 22, for 22:00. I’m trying to combine these two elements into a proper timestamp, with date, hours, minutes, seconds. How can I accomplish this? What I’ve tried so far However, I g…