: when the execution of the along while have no reaction, feel infinite loop, this table for the filtered data in 50, how half a day did not find, also don't complain,
May I ask you a great god is what went wrong, look,
SQL statements:
With SZX as
(
Select fID, BMonFM, path=cast (fID as varchar (8000)), total=cast (BMonFM as float) from PFunMaster
Where XAudit='approved' and XMark='PAYBOR' and
ProFidFM='3 eda82c0fcd94082a81649eacbc146d4 and EntFidFM like' % % 3 e85069351664628b0315e962df01f92 and StatFM!
='completely cancel after verification'Union all
The select b. ID, b.B MonFM, Amy polumbo ath + '-' + rtrim (b. ID), a.t otal + b.B MonFM
The from SZX a join PFunMaster b on a.f ID
The select fid, BMonFM from PFunMaster, (select top 1 path from SZX where total=90000 order by newid (), a
Where charindex (' - '+ rtrim (fID) +' - ', '-' + path + '-') & gt; 0
CodePudding user response:
My own simulates a similar table data:If object_id (' (TB) ') is not null drop table (TB)
Go
The create table (TB) (ID varchar (100), [NUM] a decimal (12, 2))
Insert/TB
Select the '04 cda1a1ebb449a8a85164247cbc56ce', 60000.00 union all
30000.00 union all select '133 bf79053fc46388d29fc582aa28126'
Union all select 1 d357a18b62c4d01bb78334342412d03, 20000.00
50000.00 union all select '24 f9e6a3e3c449f5841c261c95e91044'
40000.00 union all select '2 def71ff78bd408f8118b617ee8abd3f'
Union all select 37 c5ce0a88d742838337f51c4496aca5, 15000.00
Union all select 3 ec5a731594b4114a49fcaa13c377816, 1948375.03
Union all select '41 d9af4603274b1cb24c517d809b2116, 100000.00
Union all select '48 debc1463c74780809b3bb4a5139964, 46130.00
Union all select 49 e104a090694179abfe9f9e98846113, 70000.00
Union all select 'four f9f72bb3a344102849eba40007cf881, 54750.00
Select '59 eb864399b54d89a04c28ee8aa6c28b, 35900.00 union all
16500.00 union all select '5 dfd6a763c8c48e4968cf23460f2fb2c'
102750.00 union all select '5 eb9ff5f52f94831a96d9ef92bd091f5'
10000.00 union all select '5 f388ce8b6e64f7dbc21cac119458168'
277142.00 union all select '683 c82d967574deeb05622d2c83e4e81'
305905.00 union all select '7291 a40b0b12496bb79cd6098c81fb49'
70000.00 union all select '7610943 b575245e4afd1205d52928deb'
120000.00 union all select '797 f3b5c24624daf8149b67c5a2c2d14'
37000.00 union all select '7 b74fc974a70472c85ab15de7027a729'
150000.00 union all select '7 f019731546243a29de063d31b95e28a'
150000.00 union all select '80 d910a621684321b6dcf200a0fbbc73'
Select '85 a6cf986123492eb968468ed83617e2, 20700.00
Go
With SZX as
(
Select ID, NUM, path=cast (ID as varchar (8000)), total=cast (NUM as float) from TB
Union all
The select b.I D, b.n um, Amy polumbo ath + '-' + rtrim (b.I D), a.t otal + b.n um
The from SZX join TB b on Anderson d
Select id, num from TB, (select top 1 path from SZX where total=90000 order by newid (), a
Where charindex (' - '+ rtrim (id) +' - ', '-' + path + '-') & gt; 0
This is no problem, is this why?
CodePudding user response:
PFunMaster, this table how many dataCodePudding user response:
Written repetitive, amount of data and computation are increase many, such as the JOIN PFunMaster b ON a.f ID & lt; B. ID AND a.t otal & lt; 90000 this, a lot of data to be repeated,For example:
WITH t1 AS (SELECT 1 AS N UNION ALL SELECT 2 AS N UNION ALL SELECT 3 AS N UNION ALL SELECT AS 4 N),
Cet AS (SELECT N FROM t1 WHERE t1, N=1 UNION ALL SELECT a.N FROM t1 to JOIN a cet ON a.N b & gt; B.N)
SELECT * FROM cet
The result is:
N
-- -- -- -- -- -- -- -- -- -- --
1
2
3
4
4
3
4
4
(8 rows affected)
CodePudding user response:
Look at the code syntax okSee
The select b. ID, b.B MonFM, Amy polumbo ath + '-' + rtrim (b. ID), a.t otal + b.B MonFM
The from SZX a join PFunMaster b on a.f ID
Simplify or some places, convenient search problem