<legend id='ta4vk'><style id='ta4vk'><dir id='ta4vk'><q id='ta4vk'></q></dir></style></legend>

    • <bdo id='ta4vk'></bdo><ul id='ta4vk'></ul>
    <tfoot id='ta4vk'></tfoot>

      1. <small id='ta4vk'></small><noframes id='ta4vk'>

        <i id='ta4vk'><tr id='ta4vk'><dt id='ta4vk'><q id='ta4vk'><span id='ta4vk'><b id='ta4vk'><form id='ta4vk'><ins id='ta4vk'></ins><ul id='ta4vk'></ul><sub id='ta4vk'></sub></form><legend id='ta4vk'></legend><bdo id='ta4vk'><pre id='ta4vk'><center id='ta4vk'></center></pre></bdo></b><th id='ta4vk'></th></span></q></dt></tr></i><div id='ta4vk'><tfoot id='ta4vk'></tfoot><dl id='ta4vk'><fieldset id='ta4vk'></fieldset></dl></div>

        带有逗号分隔结果集的 sql server 子查询

        时间:2023-10-09
          <tbody id='QEZOQ'></tbody>

        • <bdo id='QEZOQ'></bdo><ul id='QEZOQ'></ul>

          <small id='QEZOQ'></small><noframes id='QEZOQ'>

              <tfoot id='QEZOQ'></tfoot>

              • <legend id='QEZOQ'><style id='QEZOQ'><dir id='QEZOQ'><q id='QEZOQ'></q></dir></style></legend>

                  <i id='QEZOQ'><tr id='QEZOQ'><dt id='QEZOQ'><q id='QEZOQ'><span id='QEZOQ'><b id='QEZOQ'><form id='QEZOQ'><ins id='QEZOQ'></ins><ul id='QEZOQ'></ul><sub id='QEZOQ'></sub></form><legend id='QEZOQ'></legend><bdo id='QEZOQ'><pre id='QEZOQ'><center id='QEZOQ'></center></pre></bdo></b><th id='QEZOQ'></th></span></q></dt></tr></i><div id='QEZOQ'><tfoot id='QEZOQ'></tfoot><dl id='QEZOQ'><fieldset id='QEZOQ'></fieldset></dl></div>
                  本文介绍了带有逗号分隔结果集的 sql server 子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要返回一个表上的记录,我的结果集需要包含一个逗号分隔的列表.

                  我附上了一张 3 张桌子的图片.我需要执行一个选择,返回第一个表中的记录,并包含屏幕截图中第三个表中存在的最后一个 AwardFocusName.

                  所以我的结果集将返回一条记录并在其中包含 AwardFocusNames 列表(逗号分隔).

                  解决方案

                  这是我过去用来做类似事情的一个技巧.使用 SUBSTRING 函数.

                  <前>SELECT n.nominationID, 子串((SELECT ',' + naf.awardFocusName来自提名奖Focus naf加入奖Focus afON naf.awardFocusID = af.awardFocusID其中 n.nominationID = naf.nominationIDFOR XML 路径('')), 2, 1000000)来自提名 n

                  请注意,2 用于切断子选择添加到第一项的前导逗号,并且选择 1000000 作为一个大数字以表示字符串的所有其余部分".

                  I need to return records on a table and my result set needs to contain a comma separated list.

                  I have attached an image of the 3 tables. I need to do a select that returns the record in the first table and include the last of AwardFocusName that exist in the 3rd table in the screenshot.

                  So my result set would return one record and include the list of AwardFocusNames in it (comma separated).

                  解决方案

                  Here's a trick I've used in the past to do similar things. Use SUBSTRING function.

                  
                      SELECT n.nominationID
                          , SUBSTRING((
                                              SELECT ',' + naf.awardFocusName
                                              FROM NominationAwardFocus naf
                                              JOIN AwardFocus af
                                                  ON naf.awardFocusID = af.awardFocusID
                                              WHERE n.nominationID = naf.nominationID
                                              FOR XML PATH('')
                  
                                          ), 2, 1000000)
                      FROM Nomination n
                  
                  

                  Note that the 2 is used to chop off the leading comma that the subselect adds to the first item, and 1000000 is chosen as a large number to mean "all of the rest of the string".

                  这篇关于带有逗号分隔结果集的 sql server 子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Laravel 急切加载与显式连接 下一篇:在 GROUP BY 之后加入?

                  相关文章

                  <i id='2WOtb'><tr id='2WOtb'><dt id='2WOtb'><q id='2WOtb'><span id='2WOtb'><b id='2WOtb'><form id='2WOtb'><ins id='2WOtb'></ins><ul id='2WOtb'></ul><sub id='2WOtb'></sub></form><legend id='2WOtb'></legend><bdo id='2WOtb'><pre id='2WOtb'><center id='2WOtb'></center></pre></bdo></b><th id='2WOtb'></th></span></q></dt></tr></i><div id='2WOtb'><tfoot id='2WOtb'></tfoot><dl id='2WOtb'><fieldset id='2WOtb'></fieldset></dl></div>
                  • <bdo id='2WOtb'></bdo><ul id='2WOtb'></ul>

                  1. <legend id='2WOtb'><style id='2WOtb'><dir id='2WOtb'><q id='2WOtb'></q></dir></style></legend>
                    <tfoot id='2WOtb'></tfoot>

                    <small id='2WOtb'></small><noframes id='2WOtb'>