사용자 도구

사이트 도구


kb:couchbasen1ql

문서의 이전 판입니다!


Couchbase/N1QL

N1QL 기본 사항 정리

  • 윈도우즈에 설치한 경우, 방화벽을 비활성화해야한다.
    • LCB_NETWORK_ERROR(16)가 나오면 방화벽을 확인해볼 것
    • 설치시 방화벽 해제할 것인지 묻던데, 제대로 되지 않는 모양, 아니면 N1QL 관련 포트를 자동으로 해제하지 않는 걸수도…
    • 어느 포트를 사용하는 건지 체크해 봐야 하는데…
  • PRIMARY INDEX를 생성하지 않은 경우 아무 쿼리도 동작하지 않는다.
  • C SDK

SELECT

-- SELECT
SELECT name, auth
FROM books
 
-- WHERE
SELECT name, auth
FROM books 
WHERE DATE_PART_STR(published, "year") >= 2014
 
-- ORDER BY #1
SELECT name, DATE_PART_STR(published, "year") AS published
FROM books 
WHERE author = "Alastair Reynolds"
ORDER BY published
 
-- DISTINCT
SELECT DISTINCT(series), author 
FROM books
WHERE series IS NOT MISSING
ORDER BY series
 
-- ORDER BY #2
SELECT name, DATE_PART_STR(published, "year") AS published
FROM books 
WHERE series = "Foundation"
ORDER BY YEAR
 
-- GROUP BY
SELECT book, AVG(rating) AS average
FROM reviews
GROUP BY book
HAVING COUNT(*) > 100000
ORDER BY average DESC
 
-- JOIN
SELECT b.name, DATE_PART_STR(a.YEAR, "year") AS YEAR, a.name AS award
FROM awards a INNER JOIN books b
ON KEYS a.book_id
ORDER BY b.name, YEAR, award
 
-- SUBQUERY
SELECT b.name, b.author
FROM books b
WHERE EXISTS (
    SELECT id
    FROM authors
    USE KEYS b.author_id
    WHERE country = "UK")
 
-- UNION
SELECT name, "Book" AS TYPE
FROM books
WHERE favorite = TRUE
UNION ALL (
    SELECT name, "Movie" AS TYPE
    FROM movies
    WHERE favorite = TRUE)
ORDER BY name
kb/couchbasen1ql.1444786553.txt.gz · 마지막으로 수정됨: 2015/10/14 10:35 저자 excel96