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:
  • НаукаНаука

Комментарии • 22

  • @PhoenixJade25
    @PhoenixJade25 3 года назад +5

    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!!!!

  • @kanknw
    @kanknw 3 года назад +2

    Great tutorial. Precise and easy to understand

  • @juliakristavilladiego4425
    @juliakristavilladiego4425 3 года назад

    Thanks for this. Super helpful!

  • @mdimranhussain171
    @mdimranhussain171 Год назад

    Just what I needed and you explained very well and in simple.
    Thank you so much

  • @10Rmorais
    @10Rmorais 3 года назад

    great tutorial, thanks!

  • @abhisheksinghchouhan8506
    @abhisheksinghchouhan8506 4 года назад

    Thanks its really helpful!

  • @skkitchenstore3085
    @skkitchenstore3085 3 года назад

    thanks helped me with date formatting.

  • @factorise001
    @factorise001 2 года назад

    awesome!!!

  • @user-ov2ls9gz5s
    @user-ov2ls9gz5s 2 года назад

    Helped me) Nice video

  • @TheeMelloMan
    @TheeMelloMan 3 года назад

    thank you

  • @liyuanfeng497
    @liyuanfeng497 3 года назад

    thank you.

  • @dininabila2086
    @dininabila2086 11 месяцев назад

    great explanAtion

  • @joshsmart9178
    @joshsmart9178 4 года назад

    Hi again. Which is better in general between SQL Server and PostgreSQL - which I realized is what you're using

  • @ssol567
    @ssol567 Год назад

    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?

  • @reigngamer94
    @reigngamer94 2 года назад +1

    Can we use date_diff('day',return_date,rental_date)
    ???

  • @mhuppman72
    @mhuppman72 2 года назад

    How do you then filter on these dates (i.e. greater than or between dates x & y)?

    • @dollarize6412
      @dollarize6412 2 года назад

      SELECT * FROM table_name
      WHERE rental_date BETWEEN 'some_date' AND 'some_other_date';
      you can also use greater than or less than

  • @mhuppman72
    @mhuppman72 2 года назад +1

    Am I able to group by the product of a distinct 'day' date?

    • @mhuppman72
      @mhuppman72 2 года назад

      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?

    • @KentoyJohannessen
      @KentoyJohannessen Год назад

      @@mhuppman72 you can only group by non-aggregate columns

  • @michaelbradford2816
    @michaelbradford2816 Год назад

    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.

  • @vietkb99
    @vietkb99 2 года назад

    love your video but your intro keyboard facerolling is so annoying