0

我目前正在尝试使用嵌套选择语句,但我的子查询正在生成NULL值。我究竟做错了什么?

SELECT filmid,datetime,title,description,
       (
          SELECT name 
          FROM fec_client 
          WHERE filmid = 'fec_film.filmid'
       ),
       (
          SELECT rating_motivation 
          FROM fec_rating_report 
          WHERE filmid = 'fec_film.filmid'
       ) 
FROM fec_film 
ORDER BY datetime DESC
4

1 回答 1

4

删除引号,否则您不是在与 SQL 中的值进行比较,而是与字符串进行比较

SELECT filmid, datetime, title, description, 
    ( SELECT name FROM fec_client WHERE filmid = fec_film.filmid ) AS name,
    ( SELECT rating_motivation FROM fec_rating_report WHERE filmid = fec_film.filmid ) AS rating   
FROM fec_film ORDER BY datetime DESC

ps 你也可以使用'AS'关键字来命名这些列

于 2012-04-16T11:58:40.547 回答