Sabtu, 21 Agustus 2021

PostgreSQL Potong Tulisan bukan ditengah Kata

  • Get the first 50 characters of the description column
  • Determine the position of the last whitespace character of the truncated description column and subtract it from the number 50 as the second parameter in the first function above.

 SELECT 

  UPPER(c.name) || ': ' || f.title AS film_category, 
  -- Truncate the description without cutting off a word
  LEFT(description, 50 - 
    -- Subtract the position of the first whitespace character
    POSITION(
      ' ' IN REVERSE(LEFT(description, 50))
    )
  ) 
FROM 
  film AS f 
  INNER JOIN film_category AS fc 
    ON f.film_id = fc.film_id 
  INNER JOIN category AS c 
    ON fc.category_id = c.category_id;

film_categoryleft
ACTION: WEREWOLF LOLAA Fanciful Story of a Man And a Sumo Wrestler who
ACTION: WATERFRONT DELIVERANCEA Unbelieveable Documentary of a Dentist And a
ACTION: UPRISING UPTOWNA Fanciful Reflection of a Boy And a Butler who
ACTION: TRUMAN CRAZYA Thrilling Epistle of a Moose And a Boy who must
ACTION: TRIP NEWTONA Fanciful Character Study of a Lumberjack And a

Tidak ada komentar:

Posting Komentar

Ad

Related Posts Plugin for WordPress, Blogger...

Label

Do it Yourself (36) soluna (28) GoPro (27) Motorcycle (24) Roda4 (23) nouvo (19) Travelling (17) Jual (13) jupiter (11) mutasi (10) Sepeda (9) King (8) Dad (5) vw (5) office (4) Atoz (2) Jasa (1) gokart (1)