【问题标题】:SQLITE Replace Column IDs with NAMES from SEPERATE TABLE in same DBSQLITE 将列 ID 替换为同一数据库中单独表中的名称
【发布时间】:2017-02-10 23:44:25
【问题描述】:

我这里有一个可用的 sqlite 数据库 => https://www.dropbox.com/s/9cn093ns3ot2cik/drinks.db?dl=0

我正在尝试使用来自glasses.name 的正确名称显示(或替换?)drinks.glass_id

我试过了

select drinks._id DID, 
       drinks.glass_id GID,
       glasses.name GNAME,
       glasses._id GIDD 
from drinks DRNKS
     join glasses GLS
     on drinks.glass_id = glasses._id

怎么了??
我花了几个小时来查找这个。 我已经阅读了这些链接,但仍然无法弄清楚。

http://community.spiceworks.com/topic/242166-sql-query-help-convert-category-id-to-the-text-name

Replacing a pulled SQL ID value with its name from another table

How to replace fetched values with another column while querying with SQL Server 2008 R2

how to get name from another table with matching id in another table?

【问题讨论】:

  • 怎么了?你有错误吗?

标签: database sqlite


【解决方案1】:

如果您为表指定别名,则必须在任何地方使用它

select d._id DID, 
       d.glass_id GID,
       g.name GNAME,
       g._id GIDD 
from drinks d
join glasses g on d.glass_id = g._id

【讨论】:

猜你喜欢
  • 2021-09-18
  • 2019-03-31
  • 2020-11-29
  • 2022-01-16
  • 2021-03-13
  • 2019-02-22
  • 2019-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多