首页 > 解决方案 > 尝试去 。在输出期间将值转换为名称

问题描述

列中返回的值a.user_id是 ID 号。我想将它们作为名称或首字母返回,例如 1 = Chris O 或 C.ONeill

我尝试过 CASE 功能,但不知道放在哪里

SELECT DISTINCT
  sb.start_time::date AS shift_date,
  i.title AS industry,
  wl.name AS venue_name,
  w.first_name,
  w.last_name,
  MIN(cs.start_time::date) AS first_completed_shift,
  i.title AS industry,
  w.interviewed_on AS induction_date,
  d.issue_date AS edbs_issue_date,
  d.created_at AS date_dbs_added,
  a.user_id    --IS IT POSSIBLE TO GET THESE AS VALUES,e.g. a.user_id '1' = 'Chris O or C.ONeill' USING USER NAMES INSTEAD OF USER ID?
FROM shift_bookings sb
JOIN jobs j ON sb.job_id = j.id
JOIN listings l ON j.listing_id = l.id
JOIN work_locations wl ON l.venue_id = wl.id
JOIN workers w ON sb.worker_id = w.id
JOIN completed_shifts cs ON w.id = cs.worker_id
JOIN documents d ON w.id = d.documentable_id
JOIN audits a ON d.id = a.auditable_id
JOIN industries i ON j.industry_id = i.id
 WHERE sb.shift_id IN (253106)
 AND d.document_type_id = 33
 AND a.auditable_type = 'Document'
 GROUP BY
  sb.start_time::date,
  wl.name,
  w.first_name,
  w.last_name,
  i.title,
  w.interviewed_on,
  d.issue_date,
  d.created_at,
  a.user_id

a.user_id 输出将是我可以设置的其他内容

标签: postgresqlswitch-statementcasereturn-value

解决方案


推荐阅读