sqlite SQL如何显示所有列

vhipe2zx  于 2023-02-23  发布在  SQLite
关注(0)|答案(1)|浏览(211)

在开始对不起我的英语。我有问题,因为我不知道如何显示所有列从我的表。我有一个简单的 db2 表。Table RecipeTable Aggregate在列Aggregate_no_1_ID,Aggregate_no_2_ID,Aggregate_no_3_ID我想显示一个Aggregate_color从聚合表。
我尝试类似的东西,但每行显示3次。My solution我希望像下面的照片的结果。Expected result

yzuktlbb

yzuktlbb1#

您是否尝试过连接序列而不是联合序列?

select rcp.id,
       agg1.aggregate_color as color_a,
       agg2.aggregate_color as color_b,
       agg3.aggregate_color as color_c,
       rcp.aggregate_no_1_weight,
       rcp.aggregate_no_2_weight,
       rcp.aggregate_no_3_weight
  from recipez10 rcp
  left
  join aggregate as agg1
    on rcp.aggregate_no_1_id = agg1.id
  left
  join aggregate as agg2
    on rcp.aggregate_no_2_id = agg2.id
  left
  join aggregate as agg3
    on rcp.aggregate_no_3_id = agg3.id

相关问题