当前位置:网站首页>关于#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语句批量执行时间比较快。谢谢
边栏推荐
- 达梦8数据库导出导入
- Android 面试题——如何徒手写一个非阻塞线程安全队列 ConcurrentLinkedQueue?
- Turn: Charles Handy: Who you are is more important than what you do
- MRTK3 develops Hololens application - gesture drag, rotate, zoom object implementation
- Web3.0 Dapps - the road to the future financial world
- Why did they choose to fall in love with AI?
- On governance and innovation, the 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum came to a successful conclusion
- 36-Jenkins-Job迁移
- Flink 1.15.1 Cluster Construction (StandaloneSession)
- 思考(八十八):使用 protobuf 自定义选项,做数据多版本管理
猜你喜欢
The most effective seven performance testing techniques of software testing techniques
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
Open-Falcon of operation and maintenance monitoring system
基于生长的棋盘格角点检测方法
结构体初解
Kubernetes 网络入门
沃谈小知识 |“远程透传”那点事儿
How to discover a valuable GameFi?
Never put off till tomorrow what you can put - house lease management system based on the SSM
Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value
随机推荐
Open-Falcon of operation and maintenance monitoring system
Dynamic management of massive service instances
Queue Topic: Recent Requests
【七夕节】浪漫七夕,代码传情。将爱意变成绚烂的立体场景,给她(他)一个惊喜!(送代码)
What is the difference between SAP ERP and ORACLE ERP?
How to Add Category-Specific Widgets in WordPress
Use SuperMap iDesktopX data migration tool to migrate ArcGIS data
2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto
From "useable" to "easy to use", domestic software is self-controllable and continues to advance
Dameng 8 database export and import
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
Cybersecurity and the Metaverse: Identifying Weak Links
rpc-remote procedure call demo
Growth-based checkerboard corner detection method
Solana NFT开发指南
Fifteen. Actual combat - MySQL database building table character set and collation
token、jwt、oauth2、session解析
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction
2022高处安装、维护、拆除考试题模拟考试题库及在线模拟考试
[Solved] Unity Coroutine coroutine is not executed effectively