name ----+----------------...

问题描述 投票:0回答:2
It is working fine for me, check it out

here

 table: actors
 id |              name              
----+--------------------------------
  1 | Paul Rudd            
  2 | Danny Devito             
  3 | Mark Ruffalo 
  4 | David Allen Grier      

table: movies
 id |     name      | actors
----+---------------+----------------
  1 | So this is 40 |              1
  2 | Avengers      |              3
  3 | Twins         |              2

. You are not using the correct single quote

in your query.

SELECT IFNULL(m.name, 'none'), a.name
FROM actors a
JOIN movies m
ON m.id = a.id;

ERROR:  function ifnull(character varying, unknown) does not exist
LINE 1: SELECT IFNULL(n.name, 'none'), l.name

HINT:  No function matches the given name and argument types. You might need 
to add explicit type casts.
sql postgresql null relationship
2个回答
0
投票

假设我有以下表,每个表的id都是主键,第二个表的actors是第一个表的外键。我需要写一个单一的sql查询,以选择所有的电影名称和他们的演员,以及没有电影的演员。这就是我的情况。'我得到的是:

SELECT 
    coalesce(m.name, 'none'), a.name
FROM actors a
JOIN movies m
ON m.id = a.id;

0
投票

假设我有以下几个表,每个表的id都是主键 第二个表的actors是第一个表的外键 table: actors id

© www.soinside.com 2019 - 2024. All rights reserved.