SQL拼接查詢結果

表結構:

SQL拼接查詢結果_第1张图片

所需數據結構

SELECT
    c.per_type,
    c.procedures,
    c.station,
    c.band,
    STUFF(
        (
            SELECT
                ',' + STR(a.person_qty, 5, 0)
            FROM
                mes_budget_list_labour a
            WHERE
                c.per_type = a.per_type
            AND c.procedures = a.procedures
            AND c.station = a.station
            AND c.band = a.band
            AND c.serialnumber = a.serialnumber
            ORDER BY
                unit_month FOR xml path ('')
        ),1,2,'')      AS qty,
    SUM (c.total_price) AS total_price,
    c.person_rate
FROM
    mes_budget_list_labour c
WHERE
    c.serialnumber = ''
GROUP BY
    per_type,
    procedures,
    station,
    band,
    serialnumber,
    person_rate

查詢結果:

SQL拼接查詢結果_第2张图片

js處理:

for(var i=0;i         {
             gresults[i][4]=gresults[i][4].split(",");
             gresults[i] = gresults[i].join(",").split(",");
        }
      

你可能感兴趣的:(SQL)