I have a result table like this
UniqueID
Value
1
100
1
98
1
99
2
100
2
98
3
99
and I want to display the result as follows using SQL
UnqiueID
Value1
Value2
Value3
1
100
98
99
2
100
98
3
99
Please suggest queries using single table and multiple tables
Related
I use MySql and I have some problems with it ^^
Let's say I have two tables which will be "FirstTable" and "SecondTable"
First table (ID isn't the primary key)
ID IdCust Ref
1 300 123
1 300 124
2 302 345
And the second (ID isn't the primary key)
ID Ref Code Price
1 123 A 10
1 123 Y 15
2 124 A 14
3 345 C 18
[EDIT] The column "Stock" in the final result is equals to "ID" in the second table
The column "Stock", "Code" and "Price" can have x values, so I don't know it, in advance...
I make some research in stackoverflow, but I only find post where people use "count(case when ..."
Like this one : MySQL pivot row into dynamic number of columns
For my problem, I cannot use it, because i can't know in advance the value of reference
I'm trying to produce the following output:
The result I want
[EDIT] Result in TXT
ID IdCust Ref StockA Code1 Price1 StockB Code2 Price2
1 300 123 1 A 10 1 Y 15
1 300 124 2 A 14
2 300 345 3 C 18
Need queries to check below condition
SNO CLEANPRODUCT CLEANID
100 ABC 1
100 ABC 1
100 XYZ 2
101 DEF 3
101 DEF 3
101 AAA 4
Within a SNO each CLEANPRODUCT should have same CLEANID.
I want to show 50 rows in one page of the SSRS Report. But I want to show these 50 rows in two columns of 25 rows each. Is there a way to do a page break on the same page or is there any other way to achieve this?
Depending on how you want to arrange your data, you will need to have two separate tables each configured to only show 25 rows sorted so that it displayes as you require (Read across then down or down one table then the other?)
One way to do this would be to create a hidden row group as #MiguelH suggested in their comment that has two levels to it, so you group into 50s and 25s along the lines of:
Row # - Group 1 - Group 2
1 1 1
2 1 1
....
24 1 1
25 1 1
26 1 2
27 1 2
....
49 1 2
50 1 2
51 2 1
52 2 1
....
74 2 1
75 2 1
76 2 2
77 2 2
....
98 2 2
99 2 2
100 3 1
101 3 1
You can then set a page break after your table group, displaying all records with a Group 2 value of 1 in the first table and a Group 2 value of 2 in your second table on the same page.
So we got four tables T1,T2,T3,T4
Each table has four columns, id,1,x,2 (id is primary key auto incremented in all tables) and all of them are populated with numbers (40-50 rows each).
How can I compare the first field of each table and column (and same for all the remaining fields) and display the maximum field for each column and its id?
For example, compare column 1/field 1 of T1 with column 1/field 1 of T2 and column 1/field 1 of T3 display the maximum and its id and then do the same for column 2/field 1 OF T1/T2/T3/T4/ etc etc and each of their respective fields for all 40 rows ?
I have read about UNION and JOINS but I don't know how to do this.
Any help would be appreciated.
TABLE 1
ID | 1 | X | 2 |
1 10 20 30
2 5 45 6
3 3 11 12
4 0 14 23
TABLE 2
ID | 1 | X | 2 |
1 100 200 300
2 50 405 60
3 30 101 102
4 0 104 203
ETC ETC
we need to compare the 10 of table 1 column 1 row 1 id=1 with 100 of table 2 row/column/id=1 then the same for x and 2 column.
Colummn1 Column2
----------------------------
5 24
5 20
5 13
----------------------------
2 3
----------------------------
3 25
----------------------------
1 4
----------------------------
2 6
2 42
----------------------------
5 23
5 10
----------------------------
Output should be
5 57
2 3
3 25
1 4
2 48
5 33
I have two columns. I want to sum the elements of second column when the values of column 1 are same and consecutive. ie I dont want the grouped sum to contain sum of both segments of 5.
I know how to use Group by clause bit that would aggregate the two segments. Please help me write SQL query for this .