Is is quite wired that the user-defined variable in the following sentence,
SELECT
@f:=CONVERT(
IF(@c<=>CatId AND DATEDIFF(Date, @d)=1, @f, Date), DATE
) AS Begin,
@c:=CatId, @d:=Date
FROM my_table AS init
ORDER BY CatId, Date
As show in here: http://sqlfiddle.com/#!2/fddbd/83, and my_table is given by:
CREATE TABLE my_table (
Id INT(6) UNSIGNED ZEROFILL,
CatId INT,
Date DATE,
Rate INT
);
INSERT INTO my_table
VALUES
(000001, 12, '2009-07-07', 1),
(000002, 12, '2009-07-08', 1),
(000003, 12, '2009-07-09', 1),
(000004, 12, '2009-07-10', 2),
(000005, 12, '2009-07-15', 1),
(000006, 12, '2009-07-16', 1),
(000007, 13, '2009-07-08', 1),
(000008, 13, '2009-07-09', 1),
(000009, 14, '2009-07-07', 2),
(000010, 14, '2009-07-08', 1),
(000010, 14, '2009-07-10', 1);
more precisely, the variable @f is not pre-defined, and what's the logic mysql will do for the DateDiff?
<>, what a big misunderstanding! Thanks!