CREATE TABLE `wrdr_promocodes_items` (
`id` INTEGER unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
`code` VARCHAR(100) NOT NULL DEFAULT '',
`discount_amount` INT,
`discount_percent` DECIMAL(3,1),
`num_limit` INT NULL,
`date_limit` DATETIME NULL,
`description` TEXT NOT NULL,
`active` TINYINT unsigned NOT NULL DEFAULT 1
);
SELECT type, time_from, time_to
FROM manager_orders
WHERE aptid = 262707
AND cancelled_at is null
AND (
time_from <= '2021-12-07 16:12:00' + INTERVAL 30 Minute AND
time_to >= '2021-12-07 16:12:00' - INTERVAL 60 Minute
);
shell> mysqldump db_name > backup-file.sql
shell> mysql db_name < backup-file.sql
SELECT * FROM (
SELECT
product.*,
prices.price ,
ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY timestamp DESC) rn
FROM product
JOIN prices ON prices.product_id = product.id
) prices WHERE rn = 1
;
CREATE TABLE images (
image_id INTEGER AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE tags (
tag_id INTEGER AUTO_INCREMENT PRIMARY KEY,
tag VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE images_tags (
image_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL,
PRIMARY KEY (tag_id, image_id),
FOREIGN KEY (tag_id) REFERENCES tags(tag_id),
FOREIGN KEY (image_id) REFERENCES images(image_id)
);
ADD COLUMN IF NOT EXISTSреализован только в MariaDB, но не существует в MySQL 5-8.
SELECT VERSION();