英文:
Output multiple tables
问题
TABLE 1
Member | IsSubscribed |
---|---|
002 | 1 |
TABLE 2
Member | IsSubscribed |
---|---|
004 | 0 |
TABLE 3
Member | IsSubscribed |
---|---|
001 | NULL |
003 | NULL |
英文:
My SQL code generates a weekly file (let's call it #final) that I need to separate into 3 spreadsheets (subscribed, not subscribed and customers with no subscription status).
The #final table looks like this:
Member | IsSubscribed |
---|---|
001 | NULL |
002 | 1 |
003 | NULL |
004 | 0 |
I could easily export the table and filter the csv, but I want to automate this as much as possible.
I could simply write 3 SELECT
statements and uncomment them as I need them, but I'm looking for a way to automatically produce three tables
--SELECT * FROM #final WHERE IsSubscribed = 1
--SELECT * FROM #final WHERE IsSubscribed = 0
--SELECT * FROM #final WHERE IsSubscribed IS NULL
My desired output:
TABLE 1
Member | IsSubscribed |
---|---|
002 | 1 |
TABLE 2
Member | IsSubscribed |
---|---|
004 | 0 |
TABLE 3
Member | IsSubscribed |
---|---|
001 | NULL |
003 | NULL |
答案1
得分: 0
我找到了答案,我的问题是使用INTO
创建一个临时表:
SELECT
Member,
IsSubscribed
INTO #final
FROM <anothertable>
SELECT * FROM #final WHERE IsSubscribed = 1
SELECT * FROM #final WHERE IsSubscribed = 0
SELECT * FROM #final WHERE IsSubscribed IS NULL
请注意,上述内容中的SQL代码部分已被保留,不进行翻译。
英文:
I found the answer to my question was to create a temp table using INTO
SELECT
Member,
IsSubscribed
INTO #final
FROM <anothertable>
SELECT * FROM #final WHERE IsSubscribed = 1
SELECT * FROM #final WHERE IsSubscribed = 0
SELECT * FROM #final WHERE IsSubscribed IS NULL
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论