Insert Value based on One Column based on Value on another Column I just tried to set _timeStamp column to store value on the basis of HOUR of _date column and tried to create table as like below but encounter 1064 error. I'm new to mysql so help me in figuring out mine mistake.

create table `help` (`_ID` integer not null,
`_date` datetime not null,
`_timeStamp` integer not null 
        SET  (1 if HOUR(`_date`)&lt;10 else 2 if HOUR(`_date`)&lt;16 else 3 if HOUR(`_date`)&lt;24
            else -1),
PRIMARY KEY (`_ID`) 
);
What you are trying to do is to create a computed column and I am pretty sure MySQL does not support them. There are a few ways around this issue:


Do the computation in the logic that inserts the data
Create a trigger on the table to do the calculation when data is inserted/updated
Create a view to represent the data how you want it.


My personal preference would be to use a view as it is easier to maintain as is a much neater solution. Your view would look something like this:

CREATE VIEW `vwHelp`
AS
SELECT `_ID`, `_date`,
CASE
   WHEN HOUR(`_date`) &lt;10 THEN 1
   WHEN HOUR(`_date`) &lt;16 THEN 2
   WHEN HOUR(`_date`) &lt;24 THEN 3
   ELSE -1
END AS `_timestamp`
FROM `help`;