The KEEP clause will KEEP your SQL queries SIMPLE!

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ธ.ค. 2024

ความคิดเห็น • 36

  • @QueryTuner
    @QueryTuner ปีที่แล้ว +5

    It's so frustrating - the more I'm learning from these dailies, the more I'm recognizing that my current knowledge is basically very limited ... 🙂
    Great information ... keep going !
    Greetings from Germany.

    • @DatabaseDude
      @DatabaseDude  ปีที่แล้ว +3

      Every day we all get an extra 1% on the Oracle features.... it all adds up

  • @MirkoVukusic
    @MirkoVukusic ปีที่แล้ว +2

    best background of all programming channels for sure

  • @dpu11
    @dpu11 ปีที่แล้ว +2

    Wow. This going to get used lot in my SQLs from today.

  • @cosmos177
    @cosmos177 ปีที่แล้ว

    Thanks.. Great Explanation.
    I used this feature to calculate the most dominant pattern of purchase from within a group/basket of products (a,b,c - 3 products) which are identified via a Rule/Pattern found via the Association Rules ML model. The ML Model works w/o consideration of sequence or order of purchase. Using this we can improve the status quo - overall we have 10 transactions where customers have purchased (a,b,c) but the most likely sequence of purchase (dominant pattern, in sequence of purchase) is b,a,c with this occurring 6 times out of 10 overall.

  • @mohamedaminesekkai7326
    @mohamedaminesekkai7326 ปีที่แล้ว

    Well done Connor. Your explanations are so simple too. Thanks a lot

  • @lmsaravia
    @lmsaravia ปีที่แล้ว +1

    Awesome!

  • @FordTransitvan
    @FordTransitvan ปีที่แล้ว

    Thanks, love these quick videos and you explain so well.

  • @neeleshshah
    @neeleshshah ปีที่แล้ว

    Oh this is a keeper.. Thanks C

  • @anuswadh
    @anuswadh ปีที่แล้ว

    This information is so useful. You are great! Thank you

  • @vikram4755
    @vikram4755 3 หลายเดือนก่อน

    Very useful indeed, 1 question though, how is it different from FIRST_VALUE analytical function?

    • @DatabaseDude
      @DatabaseDude  3 หลายเดือนก่อน +1

      They are similar but notice KEEP works in an aggregation sense (ie, with a GROUP BY)

    • @vikram4755
      @vikram4755 3 หลายเดือนก่อน

      @@DatabaseDude Awesome :)

  • @maxreuv
    @maxreuv ปีที่แล้ว

    Great stuff, thank you!

  • @TheNelate
    @TheNelate ปีที่แล้ว

    Does this work the same way as RANK OVER (Partition ...) ?

    • @DatabaseDude
      @DatabaseDude  ปีที่แล้ว

      in the sense that you could do something like (using the demo from the video)
      case when rank() over ( partition by city order by pop desc) = 1 then city_name end
      but you'ld still end up with inline views etc

  • @cliffmathew
    @cliffmathew ปีที่แล้ว

    Are you sure the output is correct? If the data is correct the city name of Mumbai should be what should show up in the line for India. Wondering if it is a data problem or a query problem.

    • @DatabaseDude
      @DatabaseDude  ปีที่แล้ว +2

      In the table I got this - but I make no claim on up-to-dateness/accuracy of the data
      SQL> select city, population from cities
      2 where country = 'India'
      3 order by population desc;
      CITY POPULATION
      -------------- ----------
      Delhi 28514000
      Mumbai 19980000
      Kolkata 14681000
      Bangalore 11440000
      Chennai 10456000
      Hyderabad 9482000
      Ahmedabad 7681000
      Surat 6564000
      Pune 6276000
      9 rows selected.

  • @eddiehapson1730
    @eddiehapson1730 ปีที่แล้ว

    Nice

  • @staygreasy
    @staygreasy ปีที่แล้ว

    Is it necessary to use MAX()? Or can we use ANYVALUE()?

    • @DatabaseDude
      @DatabaseDude  ปีที่แล้ว +1

      Pretty much any aggregation. You could even use MIN to mess with people :-) But yes, I like the ANY_VALUE option because its more self-documenting in that sense

    • @cosmos177
      @cosmos177 ปีที่แล้ว +1

      I believe, on the off-chance that multiple cities have the same population (say, we use default =100 and not actual values) within a country, the aggregation fn breaks the tie-break and gives the max city (alphabetically ordered). Any _Value would also break the tie but result would be non-deterministic.

    • @staygreasy
      @staygreasy ปีที่แล้ว +1

      @@cosmos177 If I understand correctly, ties can be broken by adding CITY DESC to the ORDER BY, making it deterministic:
      ANY_VALUE(CITY) KEEP (DENSE_RANK FIRST ORDER BY POPULATION DESC, CITY DESC)

  • @viswapsp
    @viswapsp 2 หลายเดือนก่อน

    Thank you, Connor. Very similar video is here th-cam.com/video/Y1O7LTjhPPM/w-d-xo.html. My question is does the KEEP clause work to output the names of the cities by country with the highest population, assuming there may be more than one city in a country with the same highest population? If that is not possible, I may lean towards using our regular way of doing as it works in that case as well.

    • @DatabaseDude
      @DatabaseDude  2 หลายเดือนก่อน

      Unfortunately LISTAGG is not supported as a KEEP function currently

  • @EddiSer
    @EddiSer ปีที่แล้ว

    This is great but if more than cites have the same population, only the MAX(city) is listed, not all the cities.

    • @DatabaseDude
      @DatabaseDude  ปีที่แล้ว

      This is true, but I'd content that this is often the requirement as well