I have the following spreadsheet with source and destination data, ie someone could start their journey at source A, and end at destination D, the value returned will be '2'.
I need to recreate this in mysql, so far I have the following tables set up, how do I query this to produce the same format as the spreadsheet?
CREATE TABLE `locations` (
`name` varchar(255) NOT NULL DEFAULT '',
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `zones` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`child_single` int(11) NOT NULL,
`child_return` int(11) NOT NULL,
`adult_single` int(11) NOT NULL,
`adult_return` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
CREATE TABLE `locations_fares_lookup` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`outset` varchar(255) NOT NULL,
`destination` varchar(255) NOT NULL,
`zone` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `outset` (`outset`),
KEY `destination` (`destination`),
KEY `locations_fares_lookup_ibfk_3` (`zone`),
CONSTRAINT `locations_fares_lookup_ibfk_1` FOREIGN KEY (`outset`) REFERENCES `locations` (`name`),
CONSTRAINT `locations_fares_lookup_ibfk_2` FOREIGN KEY (`destination`) REFERENCES `locations` (`name`),
CONSTRAINT `locations_fares_lookup_ibfk_3` FOREIGN KEY (`zone`) REFERENCES `zones` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
INSERT INTO `locations` (`name`)
VALUES
('A'),
('B'),
('C'),
('D'),
('E'),
('F');
INSERT INTO `zones` (`id`, `child_single`, `child_return`, `adult_single`, `adult_return`)
VALUES
(1, 121, 111, 11, 12),
(2, 120, 215, 240, 430),
(3, 165, 260, 330, 520),
(4, 205, 335, 410, 670),
(5, 240, 385, 480, 770),
(6, 122, 223, 224, 225),
(7, 232, 323, 232, 222),
(8, 222, 333, 33, 323);
etc...
INSERT INTO `locations_fares_lookup` (`outset`, `destination`, `zone`)
VALUES
('B', 'A', 2),
('C', 'A', 2),
('D', 'A', 2),
('E', 'A', 2),
('F', 'A', 5),
('A', 'B', 2),
('C', 'B', 2),
('D', 'B', 2),
('E', 'B', 2),
('F', 'B', 5);
etc...
https://www.db-fiddle.com/f/gSnEj5QwUBmku7UKnr8UaM/1
Apologies if this already has an answer, I have searched but I'm not sure what to search for.


SELECT * FROM *? And if that's your query, isn't your problem really with spreadsheet-generation?