具有特定条件的Sql表行拆分 [英] Sql table row split with specific criteria

查看:117
本文介绍了具有特定条件的Sql表行拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友..



我想做一个SQL查询。我想拆分包含特定条件的所有行。



数量列必须< = 400

Total_Wgt列必须< ; = 4000 **

请帮助我..



样品表和输出



Dear Frnds..

I want to make an SQL query. I want to split all the rows that include a specific Criteria.

Qty Column must be <=400
Total_Wgt Column must be <=4000**
Please Help me..

Sample Table and Output

	MID	Qty	Item_Wgt	Total_Wgt
	NK-1	500	3.4	1700
	NK-2	300	7.67	2300
	NK-3	200	30	6000
	NK-4	400	14.45	5780
	NK-5	700	11.79	8250
	NK-6	900	23.61	21250

	"Criteria: Qty <= 400 and TotalWgt<=4000

Output"			
SEQ				
1	NK-1	400	3.4	1360
2	NK-1	100	3.4	340
3	NK-2	300	7.67	2300
4	NK-3	133	30	3990
5	NK-3	67	30	2010
6	NK-4	276	14.45	3988.2
7	NK-4	124	14.45	1791.8
8	NK-5	339	11.79	3996.81
9	NK-5	339	11.79	3996.81
10	NK-5	22	11.79	259.38
11	NK-6	169	23.61	3990.09
12	NK-6	169	23.61	3990.09
13	NK-6	169	23.61	3990.09
14	NK-6	169	23.61	3990.09
15	NK-6	169	23.61	3990.09
16	NK-6	55	23.61	1298.55





我尝试过:



SQL表格行分割具体标准



What I have tried:

SQL Table row Split with specific Criteria

推荐答案

这不是一个好问题 - 我们无法解决你想要做的事情。

请记住我们无法看到您的屏幕,访问您的硬盘或阅读您的想法 - 我们只能准确地输入您要输入的内容。从输入中获取输出中的每一行的方式和原因并不明显。



但是你需要做的基本事情就是创建一个临时表,并使用Cursor将输入表中的每一行处理为临时表中的单独行。然后选择临时表中的所有行。



这些应该有帮助:

SQL临时表 [ ^ ]

T-SQL:使用光标的简单示例 - Steve Stedman [ ^ ]
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. And it is not obvious how or why you get each of the multiple rows in your output from the input.

But the basic thing you will need to do is create a temporary table, and use a Cursor to process each row from your input table into separate rows in your temporary table. You then select all the rows from your temp table.

These should help:
SQL Temporary Tables[^]
T-SQL: A Simple Example Using a Cursor - Steve Stedman[^]


这篇关于具有特定条件的Sql表行拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆