如何将计数结果插入表

时间:2019-12-31 02:37:15

标签: mysql-workbench

我有这样的语法

SELECT 
    b.buyer_id
FROM order_buyer b
WHERE
    EXISTS (SELECT 1 FROM order_buyer d
            WHERE d.buyer_id = b.buyer_id AND
                  d.createdAt >= '2018-10-01' AND d.createdAt < '2019-01-01') AND
    EXISTS (SELECT 1 FROM order_buyer d
            WHERE d.buyer_id = b.buyer_id AND
                  d.createdAt >= '2018-10-01' AND d.createdAt < '2019-01-01' ) AND
    NOT EXISTS (SELECT 1 FROM order_buyer d
                WHERE d.buyer_id = b.buyer_id AND d.createdAt < '2018-10-01') group by buyer_id

如何使此语法的结果(即count的值)插入到我的新表中

1 个答案:

答案 0 :(得分:0)

INSERT INTO New_Table SELECT(然后剩下的语句)

来源:https://www.w3schools.com/sql/sql_insert_into_select.asp