如何将重复的行合并为单行唯一标识符

时间:2019-05-02 03:36:48

标签: sql sql-server group-by

如何使用唯一标识符将重复的行与不同的值组合在一起。

我已经创建了创建的SQL查询,但是对SQL语言的了解有限

SELECT CONVERT(varchar(5), aualdocs.doc_typ)
    + '.' + CONVERT(varchar(5), aualdocs.doc_yer)
    + '.' + CONVERT(varchar(5), aualdocs.doc_num)
    + '.'+ CONVERT(varchar(5), aualdocs.doc_prt) as 'Project No'
  , aualdocs.det_dte AS 'Approval Date'
  , auallnks.acc_dsc AS 'Project Owner'
  , auprparc.ttl_in1 AS 'Lot No'
  , aualadrs.hou_num AS 'House Number'
  , aualadrs.str_nme AS 'Street'
  , aualadrs.sbr_nme AS 'Suburb'
  , aualadrs.pst_cde AS 'Postcode'
  , aualrefn.dsc_no1 AS 'Description Of Works'
  , audmptyp.est_cst AS 'Value Of Works'
from aualdocs aualdocs
INNER JOIN audmptyp audmptyp on aualdocs.fmt_acc=audmptyp.mdu_fmt
INNER JOIN auallnks auallnks on aualdocs.fmt_acc=auallnks.src_acc
INNER JOIN auprlink auprlink on aualdocs.fmt_acc=auprlink.mdu_fmt
INNER JOIN aualrefn aualrefn on aualdocs.ddn_cd2=aualrefn.ref_val
LEFT JOIN aupraddr aupraddr on auprlink.pcl_num=aupraddr.pcl_num
LEFT JOIN auprparc auprparc on auprlink.pcl_num=auprparc.pcl_num
LEFT JOIN aualadrs aualadrs on aupraddr.aladrs_key_num=aualadrs.key_num
where aualdocs.doc_typ='6' and aualdocs.det_cde='ADA'
and auallnks.lnk_typ='152' and aualrefn.ref_typ='bld_typ'
and audmptyp.est_cst>0 order by aualdocs.fmt_acc ASC

我所获得的结果如图片所示

SQL Query Results

我要实现的目标是作为示例

Result to Achieve

0 个答案:

没有答案