zoukankan      html  css  js  c++  java
  • 典型SQL 语句总结

    1 记录时间:2007-11-9
    表Ta:
    IDA       name           remark
    001     XXX             BBBBB
    002     YYY             CCCCC
    ……
    表Tb:
    IDB             Name         Fee               IDA(这个字段一A中的ID对应)
    b001           运费         100.00         001
    b002           代理费     150.00         001
    b003           杂费         50.00           001
    b004           运费         200.00         002
    b005           业务费     300.00         002
    ……
    现在想要得到如下结果:
    IDA       name           remark         Fee
    001     XXX             BBBBB             运费100.00   代理费150.00   杂费50.00
    002     YYY             CCCCC             运费200.00   业务费300.00
    ……
    解答:
    CREATE FUNCTION [dbo].[SumStr](@IDA varchar(50))
    RETURNS varchar(500)
    AS
    begin
    declare @Fee varchar(500)
        set @Fee=''
        select @Fee=@Fee+Name+cast(Fee as varchar)+'  ' from Tb where IDA=@IDA
        set @Fee=rtrim(@Fee)
        return @Fee
    end

    select *, Fee=dbo.SumStr(IDA) from Ta

  • 相关阅读:
    P2622 关灯问题II(关灯问题)
    P1140 相似基因
    Choose and Divide UVa 10375
    Disgruntled Judge UVA
    Color Length UVA
    P1052 过河
    P1026 统计单词个数
    Balanced Number HDU
    The SetStack Computer UVA
    Urban Elevations UVA
  • 原文地址:https://www.cnblogs.com/hhq80/p/996452.html
Copyright © 2011-2022 走看看