0

I created this table (results) in my sql database (test)

CREATE DATABASE `test`; 
USE `test`;
CREATE TABLE `results` (
`number` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id_machine` int(10) unsigned NOT NULL,
`value` float NOT NULL,
`datetime` datetime NOT NULL,
PRIMARY KEY (`number`),
UNIQUE KEY `indice_UNIQUE` (`number`)
) ENGINE=InnoDB AUTO_INCREMENT=100; 

I have the following results

8, 22.22, 42.56, 8.95, 3.64

I would like to save my data in my table in this way:

Number  id_machine   value      datetime  
 101         8       22.22     2013-06-05 14:03:00
 102         8       42.56     2013-06-05 14:03:00
 103         8        8.95     2013-06-05 14:03:00
 104         8        3.64     2013-06-05 14:03:00

Is there any easy way to do this query?

Something like

char query[]="INSERT INTO results(`id_machine`,`value`) VALUES(......)";
1

1 Answer 1

1

This, perhaps?

insert into `results` (`id_machine`, `value`, `datetime`)
values (8, 22.22, '2013-06-05 14:03:00'),
       (8, 42.56, '2013-06-05 14:03:00'), 
       (8, 8.95,  '2013-06-05 14:03:00'),
       (8, 3.64, '2013-06-05 14:03:00');

SQLFiddle here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.