sum (case when order.id is null then 0 else 1 end) order,
sum (case when cat.id is null then 0 else 1 end) cat,
prod.name,
prod.product_id
Как это реализовывается не нашел ни в одном из общедоступных источников в интернете.
SELECT partnum,
LAG(partnum) OVER w AS 'prev_partnum',
partnum - LAG(partnum) OVER w AS 'diff'
FROM nspcl
WINDOW w AS (ORDER BY id);
SELECT ShippingOffer.shipping_starts_at,
ShippingOffer.station_id,
s.name as StationName --<
FROM ShippingOffer
JOIN ShippingRequest USING (station_id)
LEFT JOIN station as s ON s.id = ShippingOffer.station_id --<
WHERE ShippingOffer.station_id_end = ShippingRequest.station_id_end
CREATE TABLE `TAB001_TYPE` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `TAB002_FIELD` (
`id` INT NOT NULL AUTO_INCREMENT,
`t001_id` INT NOT NULL,
`field_name` TEXT NOT NULL,
`field_note` TEXT NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `TAB004_DOC_VALUE` (
`id` INT NOT NULL AUTO_INCREMENT,
`t003_id` INT NOT NULL,
`t002_id` INT NOT NULL,
`value` varchar NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `TAB003_DOCS` (
`id` INT NOT NULL AUTO_INCREMENT,
`t001_id` INT NOT NULL,
`doc_name` TEXT NOT NULL,
`doc_num` INT NOT NULL,
PRIMARY KEY (`id`)
);
ALTER TABLE `TAB002_FIELD` ADD CONSTRAINT `TAB002_FIELD_fk0` FOREIGN KEY (`t001_id`) REFERENCES `TAB001_TYPE`(`id`);
ALTER TABLE `TAB004_DOC_VALUE` ADD CONSTRAINT `TAB004_DOC_VALUE_fk0` FOREIGN KEY (`t003_id`) REFERENCES `TAB003_DOCS`(`id`);
ALTER TABLE `TAB004_DOC_VALUE` ADD CONSTRAINT `TAB004_DOC_VALUE_fk1` FOREIGN KEY (`t002_id`) REFERENCES `TAB002_FIELD`(`id`);
ALTER TABLE `TAB003_DOCS` ADD CONSTRAINT `TAB003_DOCS_fk0` FOREIGN KEY (`t001_id`) REFERENCES `TAB001_TYPE`(`id`);