Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

How to create a SQL database based on parameter being met in another database

I currently have a large database with a couple hundred thousand rows and I am trying to filter down to meet certain parameter for a new table.

I currently have the code:

SELECT sym, tstamp, COUNT(*) AS trades 
FROM datas 
GROUP BY sym, tstamp 
HAVING COUNT(tstamp) > 300 

Which gives me the filtered table that I am looking for. However I am stuck from here on how to create a new table once I have this result. I'm sure this is fairly straightforward but I have been stuck on it for a couple of hours.

This is the code I am trying to use:

"INSERT INTO newdb SELECT * FROM datas 
 WHERE sym, tstamp, COUNT(*) AS trades 
 FROM datas GROUP BY sym, tstamp 
 HAVING COUNT(tstamp) > 300"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like you just have an extra SELECT * FROM datas in there.

INSERT INTO tradecounts
SELECT
    sym,
    tstamp,
    COUNT(*) AS trades
FROM
    datas
GROUP BY
    sym,
    tstamp
HAVING COUNT(tstamp) > 300

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...