I wanted to try out something that first seemed to be quite
simple, but then I had to see that I didn't manage to get the
desired result in one single query. Maybe one of you has an idea
how to do it.
Here's the table that you need for this example and a little
Stored Procedure to quickly fill the table:
CREATE TABLE tt (
id int unsigned NOT NULL auto_increment,
d1 int unsigned NOT NULL,
d2 int unsigned NOT NULL,
PRIMARY KEY (id),
KEY d1 (d1)
) ENGINE=InnoDB;
... and the Stored Procedure ...
DELIMITER //[Read more]
DROP PROCEDURE IF EXISTS insertIntoTT //
CREATE PROCEDURE insertIntoTT(in _rows int)
begin
declare counter int default 0;
while counter < _rows do
set @a := floor(rand() * 20) + 1;
set @b := floor(rand() * 1000000);
insert into tt (d1, d2) values (@a, @b);
set counter := counter + 1;
end …