Skip to content

Tag: date

Hive trunc date format issues

I am trying to convert GP to Hive migration logic but below statement giving the wrong output while execute query: output for GP : 2021-12-31 similar if we converted Hive query out put if Hive query : 2022-01-02 i could see the difference of the date. please help me. Thanks Answer You are subtracting interval…

How to cast this integer value to date in MySQL

i have airbnb data and i want to cast column last_reviews (which datatype is int) to date this is my sql code http://sqlfiddle.com/#!9/b5ea42/31 how do i cast int > date? or how do i create last_reviews column as datatype date? Answer The last_review date seems to be the number of days since 1900-01-01 so …

Raw SELECT (without FROM) of most recent 7 days to current

I want to get the query result (e.g. to populate table) of last 7 dates (without times). I know that we can select some scalars without FROM statement. So I ended up with following solution: Please point me to better (and more elegant) solution if there is one. Answer The VALUES, table value constructor, is a…

Oracle procedure saving SYSDATE

As part of a larger procedure I’m trying to write some code, which saves SYSDATE into a variable but I’m running into a problem. I narrowed it down to the following. Can someone please help me out. Answer In PLSQL you can just assign: if you insist on sql all you have to do is to add into after se…

How can I partition by group that falls within a time range?

I have the following table showing when customers bought a certain product. The data I have is CustomerID, Amount, Dat. I am trying to create the column ProductsIn30Days, which represents how many products a customer bought in the range Dat-30 days inclusive the current day. For example, ProductsIn30Days for …