![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
SQL Server
文章平均质量分 71
菜鸟记录
能力有限水平一般,努力学习,混口饭吃
展开
-
SQL 外键ID数组关联查询拼接字符串
标题不重要,理解意思就行。 表Test id pids 1 1,2,3 2 2,4 2 3,4,5 表Tab id txt 1 txt1 2 txt2 3 txt4 ………… 要得到的结果是 id pids txts 1 1,2,3 txt1,txt2,txt3, 2 2,4 txt2,txt4, ………… select id,pids (select txt + ',' from ( select a.id,b.txt原创 2020-12-04 16:23:10 · 799 阅读 · 0 评论 -
多层级关联结构表计算SQL
最近在搞一个项目,一方面表结构比较复杂,客户需求也比较复杂一些,二一个是个人SQL水平不高,导致SQL写的特别复杂,查询速度也不快,后来稍微优化了一下,做个记录。 表结构类似这种 id mlfb qty unitprice parentid 1 mlafb1 1 3 null 2 mlfb2 2 4 1 3 mlfb3 3 5 2 4 mlfb4 4 6 3 因为是层级关联的如果计算实际“mlfb4”的数量,那么久应该是4x3x2x1=24。 用SQL查询的话 select原创 2020-09-28 10:05:52 · 625 阅读 · 0 评论