create or replace view rowgen as

SELECT  @curRow := @curRow + 1 AS row_number
FROM    SENSREAD 
JOIN    (SELECT @curRow := 0) r
WHERE   @curRow<86400;

CREATE OR REPLACE VIEW generator_16
AS SELECT 0 n UNION ALL SELECT 1  UNION ALL SELECT 2  UNION ALL 
   SELECT 3   UNION ALL SELECT 4  UNION ALL SELECT 5  UNION ALL
   SELECT 6   UNION ALL SELECT 7  UNION ALL SELECT 8  UNION ALL
   SELECT 9   UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL
   SELECT 12  UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL 
   SELECT 15;

 select * from generator_16

CREATE OR REPLACE VIEW generator_256 AS
select (hi.n*16+lo.n) as n
  from generator_16 lo, generator_16 hi
 
  SELECT ( ( hi.n << 4 ) | lo.n ) AS n
     FROM generator_16 lo, generator_16 hi;

CREATE OR REPLACE VIEW generator_4k AS 
select
((`hi`.`n` * 256) + `lo`.`n`) AS `n`
from `pucon`.`generator_256` `lo`
join `pucon`.`generator_16` `hi`
;


 SELECT ( ( 'hi'.'n' << 8 ) | 'lo'.'n' ) AS n
--  SELECT (hi.n*256+lo.n) as n
     FROM generator_256 lo, generator_16 hi;


CREATE OR REPLACE VIEW generator_64k as 
select
((`hi`.`n` << 8) | `lo`.`n`) AS `n`
from `pucon`.`generator_256` `lo`
join `pucon`.`generator_256` `hi`
;



AS SELECT ( ( hi.n << 8 ) | lo.n ) AS n
     FROM generator_256 lo, generator_256 hi;


CREATE OR REPLACE VIEW generator_1m AS 
SELECT ( ( hi.n << 16 ) | lo.n ) AS n
     FROM generator_64k lo, generator_16 hi;

select * from SENSREAD where READTIME>(SUBTIME(NOW(), '02:00:00')) and SENSOR=4 and UNIT='TEMPDC' order by READTIME asc

select * from generator_1m 
  where n>1000 and n<1050

SELECT UNIX_TIMESTAMP('2015-01-01 12:00:00');

select -- UNIX_TIMESTAMP(sr.READTIME),
       sr.*
  from SENSREAD sr
  where sr.READTIME>(SUBTIME(NOW(), '02:00:00')) -- and sr.SENSOR=4 
    and sr.UNIT='TEMPDC' 
  order by sr.READTIME asc

select  g.n, 
  from generator_32bit g