Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/04/2012, 00:57
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: vista desobediente!!

Código MySQL:
Ver original
  1. select week(`tbl_1351_fisiologia`.`fechahora`,0) AS `Semana`,
  2.           cast(`tbl_1351_fisiologia`.`fechahora` as date) AS `Fecha`,
  3.           `tbl_1550_ciclo`.`wop` AS `Semana_planta`,
  4.           `tbl_1550_ciclo`.`woc` AS `Semana_ciclo`,
  5.             concat_ws(` `,`tbl_1550_ciclo`.`wop`,`tbl_1550_ciclo`.`ciclo`) AS `orden`,
  6.           `tbl_1550_ciclo`.`ciclo` AS `Ciclo`,`tbl_1070_predios`.`nombre` AS `Nombre_predio`,
  7.            `tbl_1350_fisiologia_puntos`.`alia s` AS `Muestra`,
  8.            `tbl_1110_cuestionarios`.`pregunta` AS `Pregunta`,
  9.            `tbl_1352_cuestionario_fisiologia`.`res puesta` AS `Planta_1`,
  10.            `tbl_1352_cuestionario_fisiologia`.`res puesta2` AS `Planta_2`,
  11.            `tbl_1352_cuestionario_fisiologia`.`res puesta3` AS `Planta_3`,
  12.            `tbl_1352_cuestionario_fisiologia`.`res puesta4` AS `Planta_4`,
  13.            `tbl_1352_cuestionario_fisiologia`.`res puesta5` AS `Planta_5`,
  14.            (((((`tbl_1352_cuestionario_fisiologia` .`respuesta` +
  15.                  `tbl_1352_cuestionario_fisiologia`.`respuesta2`) +
  16.                  `tbl_1352_cuestionario_fisiologia`.`respuesta3`) +
  17.                  `tbl_1352_cuestionario_fisiologia`.`respuesta4`) +
  18.                  `tbl_1352_cuestionario_fisiologia`.`respuesta5`) / 5) AS `Promedio`,
  19.                  `tbl_1351_fisiologia`.`punto_id` AS `Punto_id`,
  20.                  `tbl_1351_fisiologia`.`id` AS `Muestra_id`
  21. from (((((`tbl_1351_fisiologia` join `tbl_1070_predios`)
  22.                   join `tbl_1352_cuestionario_fisiologia`)
  23.                   join `tbl_1350_fisiologia_puntos`)
  24.                   join `tbl_1110_cuestionarios`)
  25.                   join `tbl_1550_ciclo`)
  26. where ((`tbl_1352_cuestionario_fisiologia`.`fisiologia_i d` = `tbl_1351_fisiologia`.`id`)
  27.              and (`tbl_1350_fisiologia_puntos`.`id` = `tbl_1351_fisiologia`.`punto_id`)
  28.               and (`tbl_1350_fisiologia_puntos`.`predio_id` = `tbl_1070_predios`.`id`)
  29.               and (`tbl_1110_cuestionarios`.`id` = `tbl_1352_cuestionario_fisiologia`.`cuestionario_i d`)
  30.               and (`tbl_1550_ciclo`.`predio_id` = `tbl_1070_predios`.`id`)
  31.               and (`tbl_1550_ciclo`.`woy` = week(`tbl_1351_fisiologia`.`fechahora`,0)));

Manual
  • CONCAT(str1,str2,...)
    Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example:
    SELECT CONCAT(CAST(int_col AS CHAR), char_col); CONCAT() returns NULL if any argument is NULL.
  • mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQL'
  • mysql> SELECT CONCAT('My', NULL, 'QL'); -> NULL
  • mysql> SELECT CONCAT(14.3); -> '14.3'
  • For quoted strings, concatenation can be performed by placing the strings next to each other:
  • mysql> SELECT 'My' 'S' 'QL'; -> 'MySQL'
  • CONCAT_WS(separator,str1,str2,...)
    CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments. If the separator is NULL, the result is NULL.
  • mysql> SELECT CONCAT_WS(',','First name','Second name','Last Name'); -> 'First name,Second name,Last Name'
  • mysql> SELECT CONCAT_WS(',','First name',NULL,'Last Name'); -> 'First name,Last Name'
  • CONCAT_WS() does not skip empty strings. However, it does skip any NULL values after the separator argument.

Una sugerencia JOIN Syntax
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.