当前位置:网站首页>关于#SQL#的迭代、父子结构查询问题,如何解决?
关于#SQL#的迭代、父子结构查询问题,如何解决?
2022-08-05 03:32:00 【CSDN问答】
我用的SQLSERVER数据库,有一个商品分类表,一个商品表。 商品分类表中有上下级关系,用parentid来连接。商品表中一个商品只有一个分类ID,现在想查询所有商品的分类及分类上上级、上上级 。想加个中间表来保存商品和分类的关系,以便于查询。C#用的EF。
数据表参考
商品表
ID | CategoryID | 商品名称 |
---|---|---|
1 | 100101 | 商品1 |
2 | 2001 | 商品2 |
分类表
ID | ParentID | 分类名称 |
---|---|---|
10 | NULL | 分类1 |
1001 | 10 | 分类11 |
100101 | 1001 | 分类111 |
20 | NULL | 分类2 |
2001 | 20 | 分类22 |
想要查询的结果
商品ID | 分类ID |
---|---|
1 | 10 |
1 | 1001 |
1 | 100101 |
2 | 20 |
2 | 2001 |
期望能给我sql语句,不用程序来实现。数据量比较大,sql语句批量执行时间比较快。谢谢
边栏推荐
- This year's Qixi Festival, "love vegetables" are more loving than gifts
- 【已解决】Unity Coroutinue 协程未有效执行的问题
- 思考(八十八):使用 protobuf 自定义选项,做数据多版本管理
- 运维监控系统之Open-Falcon
- 2022高处安装、维护、拆除考试题模拟考试题库及在线模拟考试
- .NET应用程序--Helloworld(C#)
- Use @Mapper to query the partition status of oracle and report an error
- 为什么pca分量没有关联
- Beyond YOLO5-Face | YOLO-FaceV2 officially open source Trick+ academic point full
- 905. 区间选点
猜你喜欢
引领数字医学高地,中山医院探索打造未来医院“新范式”
用CH341A烧录外挂Flash (W25Q16JV)
10 years of testing experience, worthless in the face of the biological age of 35
沃谈小知识 |“远程透传”那点事儿
[Solved] Unity Coroutine coroutine is not executed effectively
Solana NFT开发指南
After the large pixel panorama is completed, what are the promotion methods?
Why is the pca component not associated
事件解析树Drain3使用方法和解释
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
随机推荐
How to Add Category-Specific Widgets in WordPress
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
.NET应用程序--Helloworld(C#)
Never put off till tomorrow what you can put - house lease management system based on the SSM
presto启动成功后出现2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer
[Storage] Dawning Storage DS800-G35 ISCSI maps each LUN to the server
ASP.NET application--Hello World
Use CH341A to program external Flash (W25Q16JV)
905. 区间选点
token、jwt、oauth2、session解析
Linux下常见的开源数据库,你知道几个?
测试薪资这么高?刚毕业就20K
冒泡排序与快速排序
Step by step how to perform data risk assessment
From "useable" to "easy to use", domestic software is self-controllable and continues to advance
ffmpeg pixel format basics
STM32 uses stm32cubemx LL library series tutorial
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction
大像素全景制作完成后,推广方式有哪些?
markdown如何换行——md文件