Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
About CrossTab Query or similar query
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00804158
Message ID:
00805514
Views:
31
Try
SELECT ;
		type, orderno, model, crow, colour, IO, htyp, ;
		SUM(S1) AS sum_s1, ;
		SUM(M1) AS sum_m1, ;
		SUM(L1) AS sum_l1, ;
		SUM(X1) AS sum_x1, ;
		SUM(L2) AS sum_l2 ;
	FROM mytable ;
	GROUP BY type, orderno, model, crow, colour, IO, htyp ;
	INTO CURSOR crsSum


SELECT ;
		type, orderno, model, crow, colour, ;
		SUM(IIF(io=1, sum_s1, 0)) - SUM(IIF(io=2, sum_s1, 0)) AS diff_s1 ;
	FROM crsSum	;
	GROUP BY type, orderno, model, crow, colour ;
	INTO CURSOR crsDiffTemp

SELECT ;
		type, orderno, model, crow, colour, ;
		IIF(diff_s1>0, diff_s1, 0) AS diff_s1 ;
	FROM crsSum	;
	INTO CURSOR crsDiff
	
>Hi All,
>i have original data like below and its related with textile sector ... i want to sum I/O actions group by orderno,crow,I/O,htyp and show its on the one row group by orderno,crow with SQL how can i do this ?
>
>* crow means colour row number on the original data eg. 1 for L.GRIMEL 2 for D.GRIMEL
>* I/O means input-output actions 1 means output 2 means input
>* htyp means 1 ok ,2 faulty
>
>type orderno	        model	crow colour   IO htyp S1  M1   L1  X1   L2
>==== ==========        ======  ==== ======== == ==== ==  ===  === ===  ==
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  1    1 58  116  116  58  58
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  1    1 57  114  114  57  57
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  2    2 15    0    0   0   0
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  2    1 41  114  114  57  57
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  2    2 34    0    0   0   0
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  2    1 24  116  116  58  58
>
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  1    1 58  116  116  58  58
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  1    1 57  114  114  57  57
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  2    2 15    0    0   0   0
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  2    1 42  114  114  57  57
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  2    2 34    0    0   0   0
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  2    1 24  116  116  58  58
>
>finally data should be view like below
>
>type orderno	        model	crow colour   IO htyp S    M    L   X    L
>==== ==========        ======  ==== ======== == ==== ===  ===  === ===  ===
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  1    1 115  230  230 115  115
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  2    1  65  230  230 115  115
>1    BDO22HSW01	BD10-1	1    L.GRIMEL  2    2  49    0    0   0    0
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  1    1 115  230  230 115  115
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  2    1  66  230  230 115  115
>1    BDO22HSW01	BD10-1	2    D.GRIMEL  2    2  49    0    0   0    0
>also wantto calculate the I/O differences and show only differences > 0 like below
>
>for eg. S size L.GRIMEL output 115 input 65+49=114 115-114 = 1
>
>
>TIA
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform