Error with mod_wsgi - mod-wsgi

I got the following error in logs:
Queue timeout expired for WSGI daemon process
How can I resolve it?
I use Django 1.7.1 with mod_wsgi.
queue-timeout is set to 45 in conf file.
This is part of my httpd.conf, that deals with threads.
How should I change values, so that it works?
I think that one thread is not enough.
Is 5 a big number?
<IfModule mpm_worker_module>
<IfDefine !ONE_PROCESS>
ServerLimit 2
ThreadLimit 10
StartServers 1
MaxClients 20
MinSpareThreads 10
MaxSpareThreads 10
ThreadsPerChild 10
</IfDefine>
<IfDefine ONE_PROCESS>
ServerLimit 1
ThreadLimit 1
StartServers 1
MaxClients 1
MinSpareThreads 1
MaxSpareThreads 1
ThreadsPerChild 1
</IfDefine>
MaxRequestsPerChild 0
ThreadStackSize 262144
</IfModule>
<IfModule mpm_event_module>
<IfDefine !ONE_PROCESS>
ServerLimit 2
ThreadLimit 10
StartServers 1
MaxClients 20
MinSpareThreads 10
MaxSpareThreads 10
ThreadsPerChild 10
</IfDefine>
<IfDefine ONE_PROCESS>
ServerLimit 1
ThreadLimit 1
StartServers 1
MaxClients 1
MinSpareThreads 1
MaxSpareThreads 1
ThreadsPerChild 1
</IfDefine>
MaxRequestsPerChild 0
ThreadStackSize 262144
</IfModule>

Related

Find and insert a value from previous row based on a match between dimensions into the same SQL database table

Is it possible to get 'Dimension 3' values from Group 'Extension' into rows where Group is 'Finishing' and 'Primer'?
The problem is that the program sending the data into SQL does not give 'Dimension3' values for Groups 'Finishing' and 'Primer'.
Database table [3E_IDB_Aru].dbo.Material structure looks like this:
ID
P_GUID
Area
Group
Code
Variant
Dimension1
Dimension2
Dimension3
54
519AEC
0,0504
Extension
27/1 ver
sj
2520
20
110
55
519AEC
0,0504
Finishing
RAL 9005
(kein)
2520
20
0
56
519AEC
0,0504
Finishing
RAL 9010
(kein)
2520
20
0
57
519AEC
0,1008
Primer
GW201
(kein)
2520
40
0
58
519AEC
0,1008
Primer
ZW-400
(kein)
2520
40
0
59
519AEC
0,0504
Extension
27/1 ver
sj
2520
20
50
60
519AEC
0,0504
Finishing
RAL 9005
(kein)
2520
20
0
61
519AEC
0,0504
Finishing
RAL 9010
(kein)
2520
20
0
62
519AEC
0,1008
Primer
GW201
(kein)
2520
40
0
63
519AEC
0,1008
Primer
ZW-400
(kein)
2520
40
0
64
519AEC
0,0296
Extension
27/1 top
sj
1480
20
110
65
519AEC
0,0296
Finishing
RAL 9005
(kein)
1480
20
0
66
519AEC
0,0296
Finishing
RAL 9010
(kein)
1480
20
0
67
519AEC
0,0592
Primer
GW201
(kein)
1480
40
0
68
519AEC
0,0592
Primer
ZW-400
(kein)
1480
40
0
The desired result should look like this (values must be written into the same table [3E_IDB_Aru].dbo.Material):
ID
P_GUID
Area
Group
Code
Variant
Dimension1
Dimension2
Dimension3
54
519AEC
0,0504
Extension
27/1 ver
sj
2520
20
110
55
519AEC
0,0504
Finishing
RAL 9005
(kein)
2520
20
110
56
519AEC
0,0504
Finishing
RAL 9010
(kein)
2520
20
110
57
519AEC
0,1008
Primer
GW201
(kein)
2520
40
110
58
519AEC
0,1008
Primer
ZW-400
(kein)
2520
40
110
59
519AEC
0,0504
Extension
27/1 ver
sj
2520
20
50
60
519AEC
0,0504
Finishing
RAL 9005
(kein)
2520
20
50
61
519AEC
0,0504
Finishing
RAL 9010
(kein)
2520
20
50
62
519AEC
0,1008
Primer
GW201
(kein)
2520
40
50
63
519AEC
0,1008
Primer
ZW-400
(kein)
2520
40
50
64
519AEC
0,0296
Extension
27/1 top
sj
1480
20
110
65
519AEC
0,0296
Finishing
RAL 9005
(kein)
1480
20
110
66
519AEC
0,0296
Finishing
RAL 9010
(kein)
1480
20
110
67
519AEC
0,0592
Primer
GW201
(kein)
1480
40
110
68
519AEC
0,0592
Primer
ZW-400
(kein)
1480
40
110
You can use an UPDATE for this.
UPDATE Material
SET Dim3 = Dimension3
WHERE (MaterialGroup = 'Finishing' OR MaterialGroup = 'Primer')
AND Dim3 IS NOT NULL
But you may want to leave your data unchanged and do this operation in your SELECT operations instead. This is especially true if you have a great many rows already.
SELECT ID, Fieldnumber, Area, MaterialGroup, Code, Variant,
Dimension1, Dimension2, Dimension3,
CASE WHEN Dim3 IS NOT NULL THEN Dim3
WHEN MaterialGroup = 'Finishing' THEN Dimension3
WHEN MaterialGroup = 'Primer' THEN Dimension3
ELSE Dim3
END AS Dim3
You might even create a view for this purpose if that makes sense in your application.
use a cross apply between the source and target datasets. the source data set uses a case when condition to find group equal to Primer and Finishing to move dimension3 into the dim3 column
declare #tmp as table(ID int, P_GUID varchar(20), Area varchar(20), [Group] varchar(20), Code varchar(20), Variant varchar(20), Dimension1 int, Dimension2 int, Dimension3 int,Dim3 int)
INSERT INTO #tmp(ID,P_GUID, Area, [Group], Code, Variant, Dimension1, Dimension2, Dimension3, Dim3)
values
(54,'519AEC','0,0504','Extension','27/1 ver','sj',2520,20,110,NULL)
,(55,'519AEC','0,0504','Finishing','RAL 9005','(kein)',2520,20,0,NULL)
,(56,'519AEC','0,0504','Finishing','RAL 9010','(kein)',2520,20,0,NULL)
,(57,'519AEC','0,1008','Primer','GW201','(kein)',2520,40,0,NULL)
,(58,'519AEC','0,1008','Primer','ZW-400','(kein)',2520,40,0,NULL)
,(59,'519AEC','0,0504','Extension','27/1 ver','sj',2520,20,110,NULL)
,(60,'519AEC','0,0504','Finishing','RAL 9005','(kein)',2520,20,0,NULL)
,(61,'519AEC','0,0504','Finishing','RAL 9010','(kein)',2520,20,0,NULL)
,(62,'519AEC','0,1008','Primer','GW201','(kein)',2520,40,0,NULL)
,(63,'519AEC','0,1008','Primer','ZW-400','(kein)',2520,40,0,NULL)
,(64,'519AEC','0,0296','Extension','27/1 top','sj',1480,20,110,NULL)
,(65,'519AEC','0,0296','Finishing','RAL 9005','(kein)',1480,20,0,NULL)
,(66,'519AEC','0,0296','Finishing','RAL 9010','(kein)',1480,20,0,NULL)
,(67,'519AEC','0,0592','Primer','GW201','(kein)',1480,40,0,NULL)
,(68,'519AEC','0,0592','Primer','ZW-400','(kein)',1480,40,0,NULL)
update target
set
target.Dim3=source.Dim3
from #tmp as target
cross apply
(
select
case when [Group] in('Finishing', 'Primer') then Dimension3 end Dim3
from #tmp data
where target.ID=data.ID
)source
select * from #tmp
output
ID P_GUID Area Group Code Variant Dimension1 Dimension2 Dimension3 Dim3
54 519AEC 0,0504 Extension 27/1 ver sj 2520 20 110 NULL
55 519AEC 0,0504 Finishing RAL 9005 (kein) 2520 20 0 0
56 519AEC 0,0504 Finishing RAL 9010 (kein) 2520 20 0 0
57 519AEC 0,1008 Primer GW201 (kein) 2520 40 0 0
58 519AEC 0,1008 Primer ZW-400 (kein) 2520 40 0 0
59 519AEC 0,0504 Extension 27/1 ver sj 2520 20 110 NULL
60 519AEC 0,0504 Finishing RAL 9005 (kein) 2520 20 0 0
61 519AEC 0,0504 Finishing RAL 9010 (kein) 2520 20 0 0
62 519AEC 0,1008 Primer GW201 (kein) 2520 40 0 0
63 519AEC 0,1008 Primer ZW-400 (kein) 2520 40 0 0
64 519AEC 0,0296 Extension 27/1 top sj 1480 20 110 NULL
65 519AEC 0,0296 Finishing RAL 9005 (kein) 1480 20 0 0
66 519AEC 0,0296 Finishing RAL 9010 (kein) 1480 20 0 0
67 519AEC 0,0592 Primer GW201 (kein) 1480 40 0 0
68 519AEC 0,0592 Primer ZW-400 (kein) 1480 40 0 0
(NOTE: the code is run twice, because MaterialGroup 'Primer' Dimension2 value is double the value of MaterialGroup 'Extension' Dimension2 value. On the first pass 'null' values are being written into 'Primer' Dimension3 rows. The second pass will take care of this as I did not know how to nest this, if possible at all, into the first part of the code)Here is the code I used to achieve the task:
PRINT '\tAdd Dimension3 values into Material table where Dimension3 = 0'
UPDATE t
SET Dimension3 = (
SELECT Dimension3 FROM Material
WHERE
Pos_GUID = t.Pos_GUID AND Dimension1 = t.Dimension1 AND Dimension2 = t.Dimension2 AND ID = (
SELECT MAX(ID) FROM Material
WHERE
Pos_GUID = t.Pos_GUID AND Dimension1 = t.Dimension1 AND Dimension2 = t.Dimension2 AND ID < t.ID AND Dimension3 > 0 )
)
FROM Material t
WHERE t.Dimension3 = 0
PRINT '\tAdd Dimension3 values into Material table where Dimension3 = null'
UPDATE t
SET Dimension3 = (
SELECT Dimension3 FROM Material
WHERE
Pos_GUID = t.Pos_GUID AND Dimension1 = t.Dimension1 AND Dimension2 * 2 = t.Dimension2 AND ID = (
SELECT MAX(ID) FROM Material
WHERE
Pos_GUID = t.Pos_GUID AND Dimension1 = t.Dimension1 AND Dimension2 * 2 = t.Dimension2 AND ID < t.ID AND Dimension3 > 0 )
)
FROM Material t
WHERE t.Dimension3 is NULL
See the db<>fiddle here
Below is an example of the real database with some unnecessary columns removed. Here the Pos_GUID values are all mixed, but the ID numbers are always in ascending order under the same Pos_GUID:
ID
Pos_GUID
MaterialGroup
Dimension1
Dimension2
Dimension3
149
2E31E29F763844DA806B9868C403E219
Finishing
1361
19.5
0
149
519AEC1C7EB54C0B8DBC562A5194E38A
Extension
1500
18
89.5
150
2E31E29F763844DA806B9868C403E219
Primer
1361
19.5
0
150
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
1500
18
0
151
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
1500
18
0
152
2E31E29F763844DA806B9868C403E219
Finishing
551.67
19.5
0
152
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
1500
36
0
153
2E31E29F763844DA806B9868C403E219
Primer
551.67
19.5
0
153
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
1500
36
0
154
519AEC1C7EB54C0B8DBC562A5194E38A
Extension
2520
20
50
155
2E31E29F763844DA806B9868C403E219
Finishing
1361
19.5
0
155
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
0
156
2E31E29F763844DA806B9868C403E219
Primer
1361
19.5
0
156
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
0
157
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
2520
40
0
158
2E31E29F763844DA806B9868C403E219
Finishing
2000
82
0
158
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
2520
40
0
159
2E31E29F763844DA806B9868C403E219
Finishing
2000
82
0
159
519AEC1C7EB54C0B8DBC562A5194E38A
Extension
2520
20
110
160
2E31E29F763844DA806B9868C403E219
Primer
2000
164
0
160
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
0
161
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
0
162
2E31E29F763844DA806B9868C403E219
Finishing
2000
82
0
162
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
2520
40
0
Result:
ID
Pos_GUID
MaterialGroup
Dimension1
Dimension2
Dimension3
149
2E31E29F763844DA806B9868C403E219
Finishing
1361
19.5
0
149
519AEC1C7EB54C0B8DBC562A5194E38A
Extension
1500
18
89.5
150
2E31E29F763844DA806B9868C403E219
Primer
1361
19.5
0
150
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
1500
18
89.5
151
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
1500
18
89.5
152
2E31E29F763844DA806B9868C403E219
Finishing
551.67
19.5
0
152
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
1500
36
89.5
153
2E31E29F763844DA806B9868C403E219
Primer
551.67
19.5
0
153
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
1500
36
89.5
154
519AEC1C7EB54C0B8DBC562A5194E38A
Extension
2520
20
50
155
2E31E29F763844DA806B9868C403E219
Finishing
1361
19.5
0
155
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
50
156
2E31E29F763844DA806B9868C403E219
Primer
1361
19.5
0
156
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
50
157
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
2520
40
50
158
2E31E29F763844DA806B9868C403E219
Finishing
2000
82
0
158
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
2520
40
50
159
2E31E29F763844DA806B9868C403E219
Finishing
2000
82
0
159
519AEC1C7EB54C0B8DBC562A5194E38A
Extension
2520
20
110
160
2E31E29F763844DA806B9868C403E219
Primer
2000
164
0
160
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
110
161
519AEC1C7EB54C0B8DBC562A5194E38A
Finishing
2520
20
110
162
2E31E29F763844DA806B9868C403E219
Finishing
2000
82
0
162
519AEC1C7EB54C0B8DBC562A5194E38A
Primer
2520
40
110
See also this db<>fiddle with the actual database logic here

Getting total coverage considering staggered values in awk

Here is my data structure.
# id1 id2 len start end
# 9 16792 5475 4181 4232
# 11 16792 2317 1086 1137
# 11 32879 2317 8 60
# 11 32858 2317 10 52
# 11 30670 2317 17 63
# 14 12645 532 3 67
# 14 12645 532 158 222
# 14 11879 532 3 223
# 18 23847 644 64 285
# 18 30160 644 98 285
# 18 30160 644 345 477
# 18 30160 644 516 644
I want to get the coverage of id1 based on its length (column len) considering all entries start and end values.
The problem is that the multiple entries can have juxtapose values so considering the values in all entries would overrate the coverage. Also considering the smallest start value and biggest end value doesn't account for all since it can have gaps where not all length is represented.
Also, for each entrie that is included I need to add 1 so I can account for the whole coverage.
My expected result should be something like this
9 = 51 / 5475 = 0.009
11 = 108 / 2317 = 0.047
14 = 221 / 532 = 0.415
18 = 484 / 644 = 0.75

How to interpret the log output of docplex optimisation library

I am having a problem interpreting this log that I get after trying to maximise an objective function using docplex:
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
0 0 6.3105 0 10.2106 26
0 0 5.9960 8 Cone: 5 34
0 0 5.8464 5 Cone: 8 47
0 0 5.8030 11 Cone: 10 54
0 0 5.7670 12 Cone: 13 64
0 0 5.7441 13 Cone: 16 72
0 0 5.7044 9 Cone: 19 81
0 0 5.6844 14 5.6844 559
* 0+ 0 4.5362 5.6844 25.31%
0 0 5.5546 15 4.5362 Cuts: 322 1014 22.45%
0 0 5.4738 15 4.5362 Cuts: 38 1108 20.67%
* 0+ 0 4.6021 5.4738 18.94%
0 0 5.4296 16 4.6021 Cuts: 100 1155 17.98%
0 0 5.3779 19 4.6021 Cuts: 34 1204 16.86%
0 0 5.3462 17 4.6021 Cuts: 80 1252 16.17%
0 0 5.3396 19 4.6021 Cuts: 42 1276 16.03%
0 0 5.3364 24 4.6021 Cuts: 57 1325 15.96%
0 0 5.3269 17 4.6021 Cuts: 66 1353 15.75%
0 0 5.3188 20 4.6021 Cuts: 42 1369 15.57%
0 0 5.2975 21 4.6021 Cuts: 62 1387 15.11%
0 0 5.2838 24 4.6021 Cuts: 72 1427 14.81%
0 0 5.2796 21 4.6021 Cuts: 70 1457 14.72%
0 0 5.2762 24 4.6021 Cuts: 73 1471 14.65%
0 0 5.2655 24 4.6021 Cuts: 18 1479 14.42%
* 0+ 0 4.6061 5.2655 14.32%
* 0+ 0 4.6613 5.2655 12.96%
0 0 5.2554 26 4.6613 Cuts: 40 1492 12.75%
0 0 5.2425 27 4.6613 Cuts: 11 1511 12.47%
0 0 5.2360 23 4.6613 Cuts: 3 1518 12.33%
0 0 5.2296 19 4.6613 Cuts: 7 1521 12.19%
0 0 5.2213 18 4.6613 Cuts: 8 1543 12.01%
0 0 5.2163 24 4.6613 Cuts: 15 1552 11.91%
0 0 5.2106 21 4.6613 Cuts: 4 1558 11.78%
0 0 5.2106 21 4.6613 Cuts: 3 1559 11.78%
* 0+ 0 4.6706 5.2106 11.56%
0 2 5.2106 21 4.6706 5.2106 1559 11.56%
Elapsed time = 9.12 sec. (7822.43 ticks, tree = 0.01 MB, solutions = 5)
51 29 4.9031 3 4.6706 5.1575 1828 10.42%
260 147 4.9207 1 4.6706 5.1575 2699 10.42%
498 242 infeasible 4.6706 5.0909 3364 9.00%
712 346 4.7470 6 4.6706 5.0591 4400 8.32%
991 497 4.7338 6 4.6706 5.0480 5704 8.08%
1358 566 4.8085 11 4.6706 5.0005 7569 7.06%
1708 708 4.7638 14 4.6706 4.9579 9781 6.15%
1985 817 cutoff 4.6706 4.9265 11661 5.48%
2399 843 infeasible 4.6706 4.9058 15567 5.04%
3619 887 4.7066 4 4.6706 4.7875 23685 2.50%
Elapsed time = 17.75 sec. (10933.85 ticks, tree = 3.05 MB, solutions = 5)
4623 500 4.6863 13 4.6706 4.7274 35862 1.22%
What I don't understand is the following:
What is the difference between the third (Objective) and fifth column (Best integer )
How come that the third column (Objective) has higher values than the actual solution of the problem given by CPLEX which is (4.6706)
Does the values in the third column take into consideration the constraints given to the optimization problem?
This webpage didn't help me to understand neither, the explanation of Best Integer is really confusing.
Thank you in advance for your feedback.
Regards.
The user manual includes a detailed explanation of this log in section
CPLEX->User's Manual for CPLEX->Discrete Optimization->Solving Mixed Integer Programming Problems (MIP)->Progress Reports: interpreting the node log
(see https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/discr_optim/mip/para/52_node_log.html)
I suggest to have a look at
in
https://fr.slideshare.net/mobile/IBMOptimization/2013-11-informsminingthenodelog

last_value partition

Select speed, ram, price,
last_value(price) over (partition by speed, ram order by speed, ram) as lastp
from PC
PC table
code model speed ram hd cd price
1 1232 500 64 5.0 12x 600.0000
10 1260 500 32 10.0 12x 350.0000
11 1233 900 128 40.0 40x 980.0000
12 1233 800 128 20.0 50x 970.0000
2 1121 750 128 14.0 40x 850.0000
3 1233 500 64 5.0 12x 600.0000
4 1121 600 128 14.0 40x 850.0000
5 1121 600 128 8.0 40x 850.0000
6 1233 750 128 20.0 50x 950.0000
7 1232 500 32 10.0 12x 400.0000
8 1232 450 64 8.0 24x 350.0000
9 1232 450 32 10.0 24x 350.0000
speed ram price lastp
450 32 350.0000 350.0000
450 64 350.0000 350.0000
500 32 350.0000 350.0000
500 32 400.0000 350.0000
Can anyone explain why in speed 500 ram 32 lastp is 350 not 400
You can make another query based on the main one. I don't know your dbms, but you can try this in most databases.
;WITH C AS(
Select speed, ram, price,
ROW_NUMBER() over (partition by speed, ram order by speed, ram) as Rn
from tbl
)
SELECT speed, ram, price
,LAST_VALUE(price) over (partition by speed, ram order by speed , ram) as lastp
FROM C
ORDER BY speed, ram, Rn DESC
SQLFiddle for SQL Server

Group clause in SQL command

I have 3 tables: Deliveries, IssuedWarehouse, ReturnedStock.
Deliveries: ID, OrderNumber, Material, Width, Gauge, DelKG
IssuedWarehouse: OrderNumber, IssuedKG
ReturnedStock: OrderNumber, IssuedKG
What I'd like to do is group all the orders by Material, Width and Gauge and then sum the amount delivered, issued to the warehouse and issued back to stock.
This is the SQL that is really quite close:
SELECT
DELIVERIES.Material,
DELIVERIES.Width,
DELIVERIES.Gauge,
Count(DELIVERIES.OrderNo) AS [Orders Placed],
Sum(DELIVERIES.DeldQtyKilos) AS [KG Delivered],
Sum(IssuedWarehouse.[Qty Issued]) AS [Film Issued],
Sum([Film Retns].[Qty Issued]) AS [Film Returned],
[KG Delivered]-[Film Issued]+[Film Returned] AS [Qty Remaining]
FROM (DELIVERIES
INNER JOIN IssuedWarehouse
ON DELIVERIES.OrderNo = IssuedWarehouse.[Order No From])
INNER JOIN [Film Retns]
ON DELIVERIES.OrderNo = [Film Retns].[Order No From]
GROUP BY Material, Width, Gauge, ActDelDate
HAVING ActDelDate Between [start date] And [end date]
ORDER BY DELIVERIES.Material;
This groups the products almost perfectly. However if you take a look at the results:
Material Width Gauge Orders Placed Delivered Qnty Kilos Film Issued Film Returned Qty Remaining
COEX-GLOSS 590 75 1 534 500 124 158
COEX-MATT 1080 80 1 4226 4226 52 52
CPP 660 38 8 6720 2768 1384 5336
CPP 666 47 1 5677 5716 536 497
CPP 690 65 2 1232 717 202 717
CPP 760 38 3 3444 1318 510 2636
CPP 770 38 4 4316 3318 2592 3590
CPP 786 38 2 672 442 212 442
CPP 800 47 1 1122 1122 116 116
CPP 810 47 1 1127 1134 69 62
CPP 810 47 2 2250 1285 320 1285
CPP 1460 38 12 6540 4704 2442 4278
LD 975 75 1 502 502 182 182
LDPE 450 50 1 252 252 50 50
LDPE 520 70 1 250 250 95 95
LDPE 570 65 2 504 295 86 295
LDPE 570 65 2 508 278 48 278
LDPE 620 50 1 252 252 67 67
LDPE 660 50 1 256 256 62 62
LDPE 670 75 1 248 248 80 80
LDPE 690 47 1 476 476 390 390
LDPE 790 38 2 2104 1122 140 1122
LDPE 790 50 1 286 286 134 134
LDPE 790 50 1 250 250 125 125
LDPE 810 30 1 4062 4062 100 100
LDPE 843 33 1 408 408 835 835
LDPE 850 80 1 412 412 34 34
LDPE 855 30 1 740 740 83 83
LDPE 880 60 1 304 304 130 130
LDPE 900 70 2 1000 650 500 850
LDPE 1017 60 1 1056 1056 174 174
OPP 25 1100 1 381 381 95 95
OPP 1000 30 2 1358 1112 300 546
OPP 1000 30 1 1492 1491 100 101
OPP 1200 20 1 418 417 461 462
PET 760 12 3 1227 1876 132 -517
You'll see that there are some materials that have the same width and gauge yet they are not grouped. I think this is because the delivered qty is different on the orders. For example:
Material Width Gauge Orders Placed Delivered Qnty Kilos Film Issued Film Returned Qty Remaining
LDPE 620 50 1 252 252 67 67
LDPE 660 50 1 256 256 62 62
I would like these two rows to be grouped. They have the same material, width and gauge but the delivered qty is different therefore it hasn't grouped it.
Can anyone help me group these strange rows?
Your "problem" is that the deliveries occurred on different dates, and you're grouping by ActDelDate so the data splits, but because you haven't selected the ActDelDate column, this isn't obvious.
The fix is: Remove ActDelDate from the group by list
You should also remove the unnecessary brackets around the first join, and change
HAVING ActDelDate Between [start date] And [end date]
to
WHERE ActDelDate Between [start date] And [end date]
and have it before the GROUP BY
You are grouping by the delivery date, which is causing the rows to be split. Either omit the delivery date from the results and group by, or take the min/max of the delivery date.