我想选择三列(id_produkt,313,314),所以我尝试了:
create_table "preference_skills", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "user_id", default: 0
t.integer "skill_id", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "user_skills", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "user_id"
t.integer "skill_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "skills", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", default: ""
t.integer "skill_count", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
但它只返回两列:id_produkt和313。 如何获得带有别名的三列?
答案 0 :(得分:3)
试试这个SQL代码
select id_produkt,
case when id_stan_produkt = 313 then 'TAK'
else 'NIE'
end as "313",
case when id_stan_produkt = 314 then 'TAK'
else 'NIE'
end as "314"
from bp_stan_produkt where data_do is null