Skip to content

Instantly share code, notes, and snippets.

@ear7h
Last active August 27, 2017 07:55
Show Gist options
  • Save ear7h/5824d5a60abf14eda28106d02ac000dd to your computer and use it in GitHub Desktop.
Save ear7h/5824d5a60abf14eda28106d02ac000dd to your computer and use it in GitHub Desktop.
Insert values from other tables
#table declaration
CREATE TABLE `prices_by_seconds` (
`ask_price` double,
`ask_size` int(11),
`bid_price` double,
`bid_size` int(11),
`last_trade_price` double,
`symbol` varchar(8),
`updated_at` datetime
)
CREATE TABLE `sets` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`start` datetime,
`end` datetime,
`scale` int(11),
`table` varchar(32),
PRIMARY KEY (`id`)
)
INSERT INTO `sets` (`symbol`, `start`, `end`, `scale`, `table`)
SELECT `symbol` , min(`updated_at`), max(`updated_at`), 100000, 'moment'
FROM `prices_by_seconds`
WHERE DATE(`updated_at`) = DATE(NOW()) GROUP BY `symbol`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment