sql sql.sql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql sql.sql相关的知识,希望对你有一定的参考价值。
-- pripravime si temporary tabulku pro manipulaci s cenami, dovolime NULL ID (jinak to cele nebude fungovat)
DROP TEMPORARY TABLE IF EXISTS credit_voucher;
CREATE TEMPORARY TABLE credit_voucher LIKE `pricelist`;
CREATE TEMPORARY TABLE credit_backup_top LIKE `pricelist`;
ALTER TABLE credit_voucher
DROP KEY `PRIMARY`,
CHANGE `id` `id` INT(11) UNSIGNED NULL DEFAULT NULL;
ALTER TABLE credit_backup_top
DROP KEY `PRIMARY`,
CHANGE `id` `id` INT(11) UNSIGNED NULL DEFAULT NULL;
-- vezmeme si aktualni ceny pro 150GB pro CZ i SK, celkem 18
INSERT INTO credit_voucher
SELECT *
FROM pricelist
WHERE
valid_to IS NULL
AND `data_amount` = 150000000
AND `sms_number` IS NULL
AND country IN ('CZ', 'SK'); -- 9x od kazde;
INSERT INTO credit_backup_top
SELECT *
FROM pricelist
WHERE
valid_to IS NULL
AND `data_amount` = 70000000
AND `sms_number` IS NULL
AND is_highlighted = 1
AND country IN ('CZ', 'SK'); -- 9x od kazde;
BEGIN;
-- deaktivujeme puvodni ceny
UPDATE `pricelist`
SET `valid_to` = NOW()
WHERE `id` IN (
SELECT `id`
FROM credit_voucher
);
-- pripravime si kopii puvodnich cen, ktere budou platne od noveho roku
UPDATE credit_voucher
SET id = NULL, archived_id = NULL, valid_to = NULL, valid_from = '2017-01-01 00:00:00';
-- nasypeme pripravene nove ceny do tabulky
INSERT INTO `pricelist`
SELECT *
FROM credit_voucher;
-- pripravime cepickovou polozku
UPDATE credit_voucher
SET valid_from = NOW(), valid_to = '2017-01-01 00:00:00', is_highlighted = 1;
-- zlavime to nam
UPDATE credit_voucher
SET `price` = 18
WHERE `country` = 'SK';
-- aj bratom Čechom
UPDATE credit_voucher
SET `price` = 399
WHERE `country` = 'CZ';
-- nasypeme pripravene nove ceny do tabulky
INSERT INTO `pricelist`
SELECT *
FROM credit_voucher;
-- vytvoreni top polozek pro 70GB od ledna a deaktivace top polozek pro obdobi NOW() - novy rok
-- deaktivujeme puvodni ceny
UPDATE `pricelist`
SET `valid_to` = NOW()
WHERE `id` IN (
SELECT `id`
FROM credit_backup_top
);
-- pripravime si kopii puvodnich cen, ktere budou platne od noveho roku
UPDATE credit_backup_top
SET id = NULL, archived_id = NULL, valid_to = NULL, valid_from = '2017-01-01 00:00:00';
-- nasypeme pripravene nove ceny do tabulky
INSERT INTO `pricelist`
SELECT *
FROM credit_backup_top;
-- nasypeme pripravene nove ceny do tabulky
INSERT INTO `pricelist`
SELECT *
FROM credit_backup_top;
-- udelame z top 70GB polozek obycejne polozky
UPDATE credit_backup_top
SET valid_from = NOW(), valid_to = '2017-01-01 00:00:00', is_highlighted = 0;
-- nasypeme pripravene nove ceny do tabulky
INSERT INTO `pricelist`
SELECT *
FROM credit_backup_top;
-- vsechno se povedlo :)
COMMIT;
-- uklid
DROP TEMPORARY TABLE credit_voucher;
以上是关于sql sql.sql的主要内容,如果未能解决你的问题,请参考以下文章