35 lines
1.4 KiB
SQL
35 lines
1.4 KiB
SQL
SELECT c.itemPackingTypeFk,
|
|
CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color,
|
|
CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.`level`) levelV,
|
|
tc.ticketFk,
|
|
LEFT(COALESCE(et.description, zo.name, am.name),12) agencyDescription,
|
|
am.name,
|
|
t.clientFk,
|
|
CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 ,
|
|
CAST(IF(ic.code = 'plant', CONCAT(MAX(i.`size`),' cm'), COUNT(*)) AS CHAR) size,
|
|
w.code workerCode,
|
|
tt.labelCount,
|
|
IF(HOUR(t.shipped), TIME_FORMAT(t.shipped, '%H:%i'), TIME_FORMAT(zo.`hour`, '%H:%i')) agencyHour,
|
|
DATE_FORMAT(t.shipped, '%d/%m/%y') shipped,
|
|
COUNT(*) lineCount,
|
|
t.nickName
|
|
FROM vn.ticket t
|
|
JOIN vn.ticketCollection tc ON tc.ticketFk = t.id
|
|
JOIN vn.collection c ON c.id = tc.collectionFk
|
|
LEFT JOIN vn.collectionColors cc ON cc.shelve = tc.`level`
|
|
AND cc.wagon = tc.wagon
|
|
AND cc.trainFk = c.trainFk
|
|
JOIN vn.sale s ON s.ticketFk = t.id
|
|
LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
|
|
JOIN vn.item i ON i.id = s.itemFk
|
|
JOIN vn.itemType it ON it.id = i.typeFk
|
|
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
|
JOIN vn.worker w ON w.id = c.workerFk
|
|
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
|
|
LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id
|
|
LEFT JOIN vn.`zone` zo ON t.zoneFk = zo.id
|
|
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
|
|
LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk
|
|
WHERE tc.ticketFk IN (?)
|
|
GROUP BY t.id
|
|
ORDER BY cc.`code`; |