输出多个表格

huangapple go评论53阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月6日 15:09:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75358292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定