Two values in the same column

0

Hello everyone, I have the following program:

SELECT "resource"."name" "EMPLEAT",
"attendance"."name" "DATA", 
"attendance"."action" "ACCIO",
"hr_action_reason"."name" "MOTIU", 
"hr_timesheet_sheet_sheet"."date_to" "FULL" 

FROM "public"."hr_attendance" "attendance" 

INNER JOIN "public"."hr_employee" "employee" ON "attendance"."employee_id" = "employee"."id" 

INNER JOIN "public"."resource_resource" "resource" ON "employee"."resource_id" = "resource"."id" 

LEFT JOIN "public"."hr_action_reason" "hr_action_reason" ON "attendance"."action_desc" = "hr_action_reason"."id"

LEFT JOIN "public"."hr_timesheet_sheet_sheet" "hr_timesheet_sheet_sheet" ON "attendance"."sheet_id" = "hr_timesheet_sheet_sheet"."id"

I need the column: "hr_timesheet_sheet_sheet". "date_to" "FULL"

Apart from the date_to show me the date_from .. but how can I do it to show it to me in the same place? That is, I should show two dates .. I get one but not the 2 ..

Thanks!

    
asked by Montse Mkd 29.03.2017 в 22:41
source

2 answers

1

Editing your query would be something like the following:

SELECT "resource"."name" "EMPLEAT",
"attendance"."name" "DATA", 
"attendance"."action" "ACCIO",
"hr_action_reason"."name" "MOTIU", 
CONCAT_WS(" ", "hr_timesheet_sheet_sheet"."date_to", "hr_timesheet_sheet_sheet"."date_from") AS "FULL" 
FROM "public"."hr_attendance" "attendance" 
INNER JOIN "public"."hr_employee" "employee" ON "attendance"."employee_id" = "employee"."id" 
INNER JOIN "public"."resource_resource" "resource" ON "employee"."resource_id" = "resource"."id" 
LEFT JOIN "public"."hr_action_reason" "hr_action_reason" ON "attendance"."action_desc" = "hr_action_reason"."id"
LEFT JOIN "public"."hr_timesheet_sheet_sheet" "hr_timesheet_sheet_sheet" ON "attendance"."sheet_id" = "hr_timesheet_sheet_sheet"."id"

The CONCAT_WS function is used, which is used to concatenate with a separator. It has 3 parameters which are:

  • Separator. Specifies a separator added between the chains during joining.
  • String1. First chain to be united.
  • String2. Second chain to be united.

For more information, support the MySQL String functions.

  

link

     

link

    
answered by 29.03.2017 / 23:05
source
1

I recommend using the reserved word AS to avoid confusion and keep good practices, as well as you can do a concatenation of fields as follows CONCAT("hr_timesheet_sheet_sheet"."date_to", " ", "hr_timesheet_sheet_sheet"."date_from") AS "FULL"

    
answered by 29.03.2017 в 22:54