Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4030948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:32:10+00:00 2026-05-20T11:32:10+00:00

I have two tables with one named att as follows CREATE TABLE att (

  • 0

I have two tables with one named att as follows

CREATE TABLE att (
  SID varchar(50) NOT NULL, 
  CID varchar(50) NOT NULL, 
  Date date NOT NULL,
  H1 varchar(1) NOT NULL DEFAULT 0,
  H2 varchar(1) NOT NULL DEFAULT 0,
  H3 varchar(1) NOT NULL DEFAULT 0,
  H4 varchar(1) NOT NULL DEFAULT 0,
  H5 varchar(1) NOT NULL DEFAULT 0,
  H6 varchar(1) NOT NULL DEFAULT 0,
  H7 varchar(1) NOT NULL DEFAULT 0,
  H8 varchar(1) NOT NULL DEFAULT 0,
  H9 varchar(1) NOT NULL DEFAULT 0,
  H10 varchar(1) NOT NULL DEFAULT 0,
  INDEX (SID, CID)
);

The other table is per with following fields:
SID CID Per

How do I write a trigger for the following:
If an update occurs in any of the fields from h1-h0 on att table then
update the per column in the per table with the following values:
((total no of 1s – total no of 0s)/(total no of 1s + total no of 0s))/100

Thanks in advance
i Developed a Trigger,but it not working,its saying error in line 11,can you say what is the problem??

create TRIGGER `att_up` AFTER UPDATE ON `attentance`
FOR EACH ROW BEGIN
  DECLARE Zeros INT;
  DECLARE Ones INT;
  DECLARE total INT;
  DECLARE atted FLOAT;
  SELECT SUM(8-(h1+h2+h3+h4+h5+h6+h7+h8)) 
      INTO Zeros FROM attentance 
      WHERE StudID=NEW.StudID;
  SELECT SUM(h1+h2+h3+h4+h5+h6+h7+h8) 
      INTO Ones FROM attentance 
      WHERE StudID=NEW.StudID;
  SELECT SUM(8-(h1+h2+h3+h4+h5+h6+h7+h8))+ SUM(h1+h2+h3+h4+h5+h6+h7+h8) 
      INTO total FROM attentance 
      WHERE StudID=NEW.StudID;
  set atted=((ZEROS-Ones)/total)/100;
  INSERT into per(per) values (atted);
END$$
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:32:11+00:00Added an answer on May 20, 2026 at 11:32 am

    Make sure you change the delimiter before defining the trigger. Also make sure you’re using the same table and column names when you create the table and the trigger (you’re using att and attendance, and SID and StudID, in your examples).

    As it is, the trigger definition caused no error when I tested it in MySQL 5.1.55 after setting the delimiter.

    delimiter $$
    CREATE TRIGGER `att_up` 
      AFTER UPDATE ON `attendance`
    FOR EACH ROW 
    BEGIN
      DECLARE Zeros INT;
      DECLARE Ones INT;
      DECLARE total INT;
      DECLARE attend FLOAT;
      SELECT SUM(8-(h1+h2+h3+h4+h5+h6+h7+h8)), 
             SUM(h1+h2+h3+h4+h5+h6+h7+h8),
             SUM(8-(h1+h2+h3+h4+h5+h6+h7+h8)) + SUM(h1+h2+h3+h4+h5+h6+h7+h8)
        INTO Zeros, Ones, Total FROM attendance 
        WHERE SID=NEW.SID;
      SET attend=((Zeros-Ones)/total)/100;
      INSERT INTO per (SID, CID, per) values (NEW.SID, NEW.CID, attend)
        ON DUPLICATE KEY UPDATE per=attend;
    END$$
    delimiter ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one to many relationship between two tables. The many table contains
I have two table in mysql named rootpath with only one field 'root' and
I have two tables, one for bookings and one for room allocations. Booking table
I have two tables one has a three column composite key. The other needs
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables, one stores the products and quantity we have bought, the
I have two tables with the same columns, and I need to copy one
Lets say I have two tables - child and parent with many-to-one relation. What
I have two tables, we'll call them Foo and Bar , with a one
I have two mysql tables, one containing details on cars and one containing all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.