I only have version 5.5 of MySQL so the ROW_NUMBER() function does not exist. Using this as a test table:
CREATE TABLE test(recordID INT(3), row_number INT(6), netID INT(6),
var1 VARCHAR(5), var2 VARCHAR(5)) ;
INSERT INTO test VALUES
(1, 1, 2388, "Bill", "Smith"),
(2, 1, 2388, "Tom", "Smith"),
(3, 1, 2388, "Pat", "Smith"),
(4, 1, 2390, "Fred", "Smith"),
(5, 1, 2390, "John", "Smith"),
(6, 1, 2390, "Hal", "Jone"),
(7, 1, 2399, "Deb", "Jones"),
(8, 1, 2399, "Keith", "Mack");
I’ve written the following SELECT, it returns row_number as I need it but I have had no luck converting it to an UPDATE.
SELECT
@row_number:=CASE
WHEN @netID_no = netID
THEN @row_number + 1
ELSE 1
END AS row_number, recordID,
@netID_no:= netID netID, var1, var2
FROM
test,
(SELECT @netID_no:=0,@row_number:=0) as t
WHERE netID <> 0
ORDER BY
netID ASC, recordID;
I tried to make the select a MySQL variable like this;
SET @mycode:=( SELECT … etc );
UPDATE NetLog SET row_number = (@mycode) WHERE netID = @netID_no;
But I get all sorts of ambiguous syntax errors. I'm not sure how to proceed from here, would some please give me an example?