<rp id="wnpn7"><ruby id="wnpn7"></ruby></rp>
<progress id="wnpn7"><track id="wnpn7"><rt id="wnpn7"></rt></track></progress>
<ruby id="wnpn7"></ruby>
<ruby id="wnpn7"><blockquote id="wnpn7"><div id="wnpn7"></div></blockquote></ruby>

    1. <em id="wnpn7"><ruby id="wnpn7"><input id="wnpn7"></input></ruby></em>
      1. <button id="wnpn7"><acronym id="wnpn7"></acronym></button><button id="wnpn7"><acronym id="wnpn7"></acronym></button>

        <rp id="wnpn7"><acronym id="wnpn7"></acronym></rp>

        <li id="wnpn7"><object id="wnpn7"><u id="wnpn7"></u></object></li>
        VB.net 2010 視頻教程 VB.net 2010 視頻教程 python基礎視頻教程
        SQL Server 2008 視頻教程 c#入門經典教程 Visual Basic從門到精通視頻教程
        當前位置:
        首頁 > 數據庫 > SQL教程 >
        • sql教程之數據庫多行轉換為單一列

        本站最新發布    SQL Server 2016數據庫視頻教程

        試聽地址   http://www.squ68.com/eschool/SQLxin3721/

        數據庫存儲與實際顯示需求不一樣時,我們得寫SQL來實現數據呈現:

        如:

         

        先來看看數據表:

         

        復制代碼
        CREATE TABLE [dbo].[Expenses]
        (
            [Date] DATE,
            [Description] NVARCHAR(40),
            [Charge] DECIMAL(18,2)
        )
        GO
        復制代碼

         

        然后,我們為表填充一些數據,比如春節購買開支:

         

        復制代碼
        INSERT INTO [dbo].[Expenses] ([Date],[Description],[Charge]) VALUES 
        ('2020-01-22',N'魷魚',305.40),
        ('2020-01-22',N'豬肉',110.60),
        ('2020-01-22',N'青菜',36.90),
        ('2020-01-22',N'',30.00),
        ('2020-01-22',N'',75.00),
        
        ('2020-01-23',N'魷魚',200.40),
        ('2020-01-23',N'豬肉',50.00),
        ('2020-01-23',N'青菜',14.30),
        ('2020-01-23',N'',30.00),
        ('2020-01-23',N'',20.00),
        
        ('2020-01-24',N'魷魚',460.00),
        ('2020-01-24',N'豬肉',200.00),
        ('2020-01-24',N'青菜',90.00),
        ('2020-01-24',N'',50.00),
        ('2020-01-24',N'',300.00)
        
        GO
        復制代碼

         

        所有數據準備完畢,現在寫SQL來實現此功能:

         

        SELECT E1.[Date],E1.[Charge] AS N'魷魚',E2.[Charge] AS N'豬肉',E3.[Charge] AS N'青菜',E4.[Charge] AS N'', E5.[Charge] AS N''  FROM
        [dbo].[Expenses] AS E1,[dbo].[Expenses] AS E2,[dbo].[Expenses] AS E3,[dbo].[Expenses] AS E4,[dbo].[Expenses] AS E5
        WHERE E1.[Date] = E2.[Date] AND E2.[Date] = E3.[Date] AND E3.[Date] = E4.[Date] AND E4.[Date] = E5.[Date]
        AND E1.[Description] = N'魷魚' AND E2.[Description] = N'豬肉' AND E3.[Description] = N'青菜' AND E4.[Description] = N'' AND E5.[Description] = N''  
        GO

         

        相關教程
                
        免费看成年人视频大全_免费看成年人视频在线观看