- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
CREATE TRIGGER after_update_limit AFTER UPDATE ON limits
FOR EACH ROW
BEGIN
SET @annual_normative = NULL;
SET @ud_use = NULL;
SET @ud_disposal = NULL;
SET @placed_deposited = NULL;
SET @placed_disposal = NULL;
SET @custom1_disposal = NULL;
SET @custom1_deposited = NULL;
SET @custom1_use = NULL;
SET @custom1_neutralization = NULL;
SET @custom2_disposal = NULL;
SET @custom2_deposited = NULL;
SET @custom2_use = NULL;
SET @custom2_neutralization = NULL;
SET @custom3_disposal = NULL;
SET @custom3_deposited = NULL;
SET @custom3_use = NULL;
SET @custom3_neutralization = NULL;
SET @custom4_disposal = NULL;
SET @custom4_deposited = NULL;
SET @custom4_use = NULL;
SET @custom4_neutralization = NULL;
SET @custom5_disposal = NULL;
SET @custom5_deposited = NULL;
SET @custom5_use = NULL;
SET @custom5_neutralization = NULL;
SELECT
SUM(annual_normative), SUM(ud_use), SUM(ud_disposal), SUM(placed_deposited), SUM(placed_disposal),
SUM(custom1_disposal), SUM(custom1_deposited), SUM(custom1_use), SUM(custom1_neutralization),
SUM(custom2_disposal), SUM(custom2_deposited), SUM(custom2_use), SUM(custom2_neutralization),
SUM(custom3_disposal), SUM(custom3_deposited), SUM(custom3_use), SUM(custom3_neutralization),
SUM(custom4_disposal), SUM(custom4_deposited), SUM(custom4_use), SUM(custom4_neutralization),
SUM(custom5_disposal), SUM(custom5_deposited), SUM(custom5_use), SUM(custom5_neutralization)
INTO
@annual_normative, @ud_use, @ud_disposal, @placed_deposited, @placed_disposal,
@custom1_disposal, @custom1_deposited, @custom1_use, @custom1_neutralization,
@custom2_disposal, @custom2_deposited, @custom2_use, @custom2_neutralization,
@custom3_disposal, @custom3_deposited, @custom3_use, @custom3_neutralization,
@custom4_disposal, @custom4_deposited, @custom4_use, @custom4_neutralization,
@custom5_disposal, @custom5_deposited, @custom5_use, @custom5_neutralization
FROM limits
WHERE id_enterprise = NEW.id_enterprise;
UPDATE limits_total
SET
annual_normative = @annual_normative, ud_use = @ud_use, ud_disposal = @ud_disposal, placed_deposited = @placed_deposited, placed_disposal = @placed_disposal,
custom1_disposal = @custom1_disposal, custom1_deposited = @custom1_deposited, custom1_use = @custom1_use, custom1_neutralization = @custom1_neutralization,
custom2_disposal = @custom2_disposal, custom2_deposited = @custom2_deposited, custom2_use = @custom2_use, custom2_neutralization = @custom2_neutralization,
custom3_disposal = @custom3_disposal, custom3_deposited = @custom3_deposited, custom3_use = @custom3_use, custom3_neutralization = @custom3_neutralization,
custom4_disposal = @custom4_disposal, custom4_deposited = @custom4_deposited, custom4_use = @custom4_use, custom4_neutralization = @custom4_neutralization,
custom5_disposal = @custom5_disposal, custom5_deposited = @custom5_deposited, custom5_use = @custom5_use, custom5_neutralization = @custom5_neutralization
WHERE id_enterprise = NEW.id_enterprise
LIMIT 1;
END;
Сперва можно посмеяться, а затем подскажите, пжл, как тоже самое написать по человечески ???
eth0 12.09.2011 18:42 # +4
DarkThinker 14.09.2011 12:12 # −2
вроде не ошибся, а то, что совета спросил, а чего не спросить?
koodeer 14.09.2011 16:57 # +4
bugmenot 12.09.2011 19:02 # +1
Yurik 12.09.2011 19:17 # +4
actuator 13.09.2011 05:00 # 0
guest 13.09.2011 17:29 # −2
SET annual_normative = SUM(l.annual_normative)
FROM limits l
INNER JOIN limits_total lt ON l.id_enterprise = lt.id_enterprise
WHERE lt.id_enterprise = NEW.id_enterprise
DarkThinker 14.09.2011 12:10 # −1
данное решение не поддерживается в mysql именно в таком виде
долго думая и читая документацию, подстроился под подобный запрос, однако выдало 1442 ошибку (запрос ведь в триггере)
видимо лучше моего говнокода пока нет вариантов :\
eth0 14.09.2011 13:32 # 0
guest 04.10.2011 14:19 # 0
SET (annual_normative, ud_use, ud_disposal, placed_deposited, placed_disposal,
custom1_disposal, ... , custom5_neutralization) = (SELECT
SUM(annual_normative), SUM(ud_use), SUM(ud_disposal), SUM(placed_deposited), SUM(placed_disposal),
SUM(custom1_disposal), ... , SUM(custom5_neutralization)
FROM limits
WHERE id_enterprise = NEW.id_enterprise)
WHERE id_enterprise = NEW.id_enterprise
LIMIT 1
qweqwe 25.08.2021 10:12 # 0