我想做的是始终将数量为0的产品发送到已排序列表的末尾而又不丢失当前的排序(如我在以下问题中所描述的如何将零数量产品发送到PagedList 的末尾?)
所以我有一个Sorted temptable(按用户选择的字母顺序,价格或更新的产品排序):
CREATE TABLE #DisplayOrderTmp
(
[Id] int IDENTITY (1, 1) NOT NULL,
[ProductId] int NOT NULL
)
sorted #DisplayOrderTmp :
+------------+---------------+
| id | ProductId |
+------------+---------------+
| 1 | 66873 | // Qty is 0
| 2 | 70735 | // Qty is not 0
| 3 | 17121 | // Qty is not 0
| 4 | 48512 | // Qty is not 0
| 5 | 51213 | // Qty is 0
+------------+---------------+
我想通过这个数据到网页,但在此之前它,我需要与数量为零到此列表的末尾发送产品没有松动的当前排序)
我返回的数据应该是这样的(排序不会改变,只有0个数量的产品按其顺序到达了列表的末尾):
CREATE TABLE #DisplayOrderTmp4
(
[Id] int IDENTITY (1, 1) NOT NULL,
[ProductId] int NOT NULL
)
+------------+---------------+
| id | ProductId |
+------------+---------------+
| 1 | 70735 |
| 2 | 17121 |
| 3 | 48512 |
| 4 | 66873 |
| 5 | 51213 |
+------------+---------------+
PS:我的产品表,我必须与tmptable内连接以查找产品数量。
```js
Product Table is like this : +------------+---------------+------------------+
| id | stockqty | DisableBuyButton | +------------+---------------+------------------+
| 17121 | 1 | 0 | | 48512 | 27 | 0 |
| 51213 | 0 | 1 | | 66873 | 0 | 1 | | 70735 | 11 | 0 | +------------+---------------+------------------+
到目前为止,我尝试过的是:(延迟运行,并且出现性能问题,我几乎有3万种产品)
```js
INSERT INTO #DisplayOrderTmp2 ([ProductId])
SELECT p2.ProductId
FROM #DisplayOrderTmp p2 with (NOLOCK) // it's already sorted table
INNER JOIN Product prd with (NOLOCK)
ON p2.ProductId=prd.Id
and prd.DisableBuyButton=0 // to find product with qty more than 0
group by p2.ProductId order by min(p2.Id) // to save current ordering
INSERT INTO #DisplayOrderTmp3 ([ProductId])
SELECT p2.ProductId
FROM #DisplayOrderTmp p2 with (NOLOCK) //it's already sorted table
INNER JOIN Product prd with (NOLOCK)
ON p2.ProductId=prd.Id
and prd.DisableBuyButton=1 // to find product with qty equal to 0
group by p2.ProductId order by min(p2.Id) // to save current ordering
INSERT INTO #DisplayOrderTmp4 ([ProductId]) // finally Union All this two data
SELECT p2.ProductId FROM
#DisplayOrderTmp2 p2 with (NOLOCK) // More than 0 qty products with saved ordering
UNION ALL
SELECT p2.ProductId FROM
#DisplayOrderTmp3 p2 with (NOLOCK) // 0 qty products with saved ordering
有什么方法可以避免在此查询中创建TempTable?在不创建其他三个tempTable的情况下,将第一个临时表的0个数量的产品发送到数据列表的末尾,而不会丢失基于Identity ID的当前排序。我的查询出现性能问题。
我不得不再说一遍,该临时表具有标识插入ID,并且它是基于排序的排序类型,用户将其传递给存储过程。谢谢你们 :)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。