N
N
Nikita Guriev2019-11-10 21:58:21
Laravel
Nikita Guriev, 2019-11-10 21:58:21

How to write a SQL query correctly? Working with Like?


Get a list of books written by 3 or more co-authors, indicating the number of authors (no names)

SELECT * FROM books WHERE authorId LIKE '% %, % %, % %'

First Name Last Name, First Name Last Name, First Name Last Name. in one column.
For example, Stanley Lippman, Josy Lajoye, Barbara Moo.
In general, how to make it so that there are three authors (and not three like mine) and the number of authors is displayed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey c0re, 2019-11-11
@kvestor

select
     (char_length(authorId) - char_length(replace(authorId,',','')) + 1) as author_cnt
    ,b.*
  from books b
  where (char_length(authorId) - char_length(replace(authorId,',','')) + 1) >= 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question