【问题标题】:"column doesn't exist" when using a WHERE clause in joined tables [duplicate]在联接表中使用 WHERE 子句时“列不存在”[重复]
【发布时间】:2021-07-02 13:13:42
【问题描述】:

CreditCardbelongs_toUserSubscriptionbelong_to User

我正在尝试查询所有CreditCards belong_toUser 其中Subscription.status"authorized"

select * from credit_cards
join users on users.id = credit_cards.user_id
join subscriptions on users.id = subscriptions.user_id
where subscriptions.status = "authorized"

返回ERROR: column "authorized" does not exist

其中 Subscription.status = "authorized" 给了我missing FROM-clause entry for table "subscription"

我做错了什么?

【问题讨论】:

    标签: sql database postgresql


    【解决方案1】:

    SQL 中的字符串文字用单引号 (') 表示,而不是像您在查询中使用的双引号 ("):

    select * from credit_cards
    join users on users.id = credit_cards.user_id
    join subscriptions on users.id = subscriptions.user_id
    where subscriptions.status = 'authorized'
    -- Here ---------------------^----------^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      相关资源
      最近更新 更多