Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 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"
question from:https://stackoverflow.com/questions/65516750/how-to-create-a-sql-database-based-on-parameter-being-met-in-another-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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 OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...