mardi 6 juin 2017

sql subquery to get sources

I'm creating a view that display data about transferred equiments from 1 station to another, the query that creates the view display the equipment and station data in rows,

Equipment_id       station_source    Station_destiny
  1                    1(ARICA)            1(ARICA)    original station 
  1                    1(ARICA)            4(HUASCO)   Transfer 1
  1                    4(HUASCO)           1(ARICA)    final transfer

what i have in the viewview image

basically i need to order my query to display the source station as presented on the scheme above.

here my view code:

CREATE 
VIEW historial_cambios AS
SELECT equipo.id as ID, equipo.nombre as Equipo, parametro.nombre as Parametro , 
estacion.nombre as EstacionActual,
equipo_estacion.created_at as FechaCambio, equipo_estacion.estado as Estado
FROM `estacion` 
INNER JOIN equipo_estacion ON equipo_estacion.estacion_id = estacion.id 
INNER JOIN equipo ON equipo.id = equipo_estacion.equipo_id
INNER JOIN equipo_parametro ON equipo_parametro.equipo_id = equipo.id
INNER JOIN parametro ON parametro.id = equipo_parametro.parametro_id    
ORDER BY `ID` ASC 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire