How to use the DATE_TRUNC Function in SQL (vs. TO_CHAR)
HTML-код
- Опубликовано: 11 янв 2020
- In this tutorial, you'll learn how to use the DATE_TRUNC function in SQL to optimize queries using dates!
Watch the TO_CHAR video: • Using the TO_CHAR func...
Queries:
1) Truncate for the day: SELECT date, DATE_TRUNC('day',date) FROM table
2) Do some truncated date math: SELECT DATE_TRUNC('day',date1)-DATE_TRUNC('day',date2) FROM table
Get the Pagila Database: • How to Load a Sample P...
Support the Channel:
1) Subscribe: www.becomingads.com/o/youtube
2) DataCamp:
3) Udacity: Наука
Thank you so much for breaking this down into simple words to connect the concepts for us N00bs!!! Greatly appreciate the effort you put in dude. A thousand thank you's friend!!!!
Great tutorial. Precise and easy to understand
Thanks for this. Super helpful!
Just what I needed and you explained very well and in simple.
Thank you so much
great tutorial, thanks!
Thanks its really helpful!
thanks helped me with date formatting.
awesome!!!
Helped me) Nice video
thank you
thank you.
great explanAtion
Hi again. Which is better in general between SQL Server and PostgreSQL - which I realized is what you're using
In python, I'd just use a data type converter to convert the day back to a numeric. Would I be correct in saying that an alternative method would be to use the CAST function to do a similar job in Postgres SQL?
Can we use date_diff('day',return_date,rental_date)
???
How do you then filter on these dates (i.e. greater than or between dates x & y)?
SELECT * FROM table_name
WHERE rental_date BETWEEN 'some_date' AND 'some_other_date';
you can also use greater than or less than
Am I able to group by the product of a distinct 'day' date?
For example:
SELECT DISTINCT (DATE_TRUNC('day',[field])) as date, count(distinct([field])) as count
FROM database.table
GROUP BY date
ORDER BY date desc
It seems I can order by, but not group by the date?
@@mhuppman72 you can only group by non-aggregate columns
Just so you'll know, some of your links led to a demand for $399. The PC became locked and demanded a fake call to Microsoft. I got out of it by signing off the PC. I'm sure you had nothing to do with it.
love your video but your intro keyboard facerolling is so annoying