ID| Date1 | Date 2 |Total
-----------------------------------
1 | 15/02/2017 |02/02/2017 | 3 |
-----------------------------------
1 | 15/02/2017 |05/08/2017 | 3 |
-----------------------------------
1 | 15/02/2017 |12/12/2017 | 3 |
-----------------------------------
2 | 12/05/2017 |07/08/2017 | 2 |
-----------------------------------
2 | 12/05/2017 |10/08/2017 | 2 |
I have a table that is displaying data like above. I'm grouping that data on "ID" column. Values for Columns "Date1" & "Total" for a particular "ID" are the same but "Date2" value can be different in a given group.
How can i merge the cells across rows when the values are the same such that it displays like below?
ID| Date1 | Date 2 |Total
-----------------------------------
1 | 15/02/2017 |02/02/2017 | 3 |
--| |------------| |
1 | |05/08/2017 | |
--| |------------| |
1 | |12/12/2017 | |
---------------------------------|
2 | 12/05/2017 |07/08/2017 | 2 |
--| |------------| |
2 | |10/08/2017 | |
I did manage to find that "HideDuplicates" TextBox property, but while that will suppress the repetition of the cell values in adjacent rows it does not merge those duplicate cells down the column across rows
Its difficult to tell how the report is setup in terms of groups etc without seeing the design, but this is pretty simple to do from scratch.
Start with a simple table with just your detail rows, no grouping. Then right-click the detail row in the row group panel under the main report design area. Choose Add Group -> Parent Group
Choose your Date1 field in the group by drop down . Click OK and you're done.
Related
I have table and I need to transform it at horizontal mode
| id | Number | Name |
|------|------------|--------|
| 3695 | 0445458225 | Name1 |
| 3695 | 0445458228 | Name2 |
| 3695 | 0445458553 | Name3 |
| 3695 | 0445458560 | Name4 |
| 3695 | 0445458551 | Name5 |
| 3695 | 0445458561 | Name7 |
| 3695 | 0445458522 | Name8 |
| 3695 | 0445458543 | Name9 |
| 3696 | 0445458226 | Name10 |
| 3696 | 0445458540 | Name11 |
| 3696 | 0445458543 | Name12 |
| 3696 | 0445923962 | Name13 |
| 3696 | 0500266382 | Name14 |
| 3697 | 0445923962 | Name15 |
| 3697 | 0445458226 | Name16 |
| 3697 | 0500266382 | Name17 |
| 3697 | 0445458564 | Name18 |
I got it as below:
| id | Name1 | Name2 | Name3 | Name4 | Name5 | Name6 | Name7 | Name8 | Name9 | Name10 | Name11 | Name12 | Name13 |
|------ |-----------|---------- |-------|----------|----------- |-------|-------|-------|----------|--------|---------- |----------|----------|
| 3695 | 445458553 | 44518551 | | 44548560 | | | | | 44548228 | | 44548543 | | 44548225 |
| 3696 | | | | | 445923962 | | | | | | 44548543 | 44548226 | |
| 3694 | | | | | 445923962 | | | | | | 44548543 | 44548226 | |
But what I need is this:
| id | Member1 | Member2 | Member3 | Member4 | Member5 | Member6 | Member7 | Member8 | Member9 | Member10 | member11 | Name12 | Name13 |
|------|-----------|----------|----------|----------|----------|----------|---------|---------|---------|----------|----------|--------|--------|
| 3695 | 445458553 | 44518551 | 44548560 | 44548228 | 44548543 | 44548225 | | | | | | | |
| 3696 | 445923962 | 44548543 | 44548226 | | | | | | | | | | |
| 3694 | 445923962 | 44548543 | 44548226 | | | | | | | | | | |
So no empty cells, column should be named as last table also original id, numbers and names are different
every time when query runs (different group id's)
Here is my SQL-code:
TRANSFORM Avg(Nick_agents.Number) AS FirstOfNumber
SELECT Nick_agents.id
FROM Nick_agents
GROUP BY Nick_agents.id
PIVOT Nick_agents.Name;
Access has a built-in Crosstab Query Wizard that does this for you.
On the Create tab, in the Queries group, click Query Wizard.
The Queries group in the Access ribbon displays two options: Query Wizard and Query Design
In the New Query dialog box, click Crosstab Query Wizard, and then click OK.
The Crosstab Query Wizard starts.
On the first page of the wizard, choose the table or query that you want to use to create a crosstab query. For this example, select the Products table and then click Next.
[![enter image description here][2]][2]
On the next page, choose the field that contains the values that you want to use as row headings. You can select up to three fields to use as row headings sources, but the fewer row headings you use, the easier your crosstab datasheet will be to read. If you choose more than one field to supply row headings, the order in which you choose the fields determines the default order in which your results are sorted.
For this example, select Supplier IDs.Value and then click the button labeled with a > symbol. Notice that Access displays the field name along the left side of the sample query preview at the bottom of the dialog box. Click Next to continue.
Select a field to display as row headings on the Crosstab query wizard.
On the next page, choose the field that contains the values that you want to use as column headings. In general, you should choose a field that contains few values, to help keep your results easy to read. For example, using a field that has only a few possible values (such as gender) might be preferable to using a field that can contain many different values (such as age).
If the field that you choose to use for column headings has the Date/Time data type, the wizard adds a step that lets you specify how to group the dates into intervals, such as months or quarters.
For this example, select Category and notice that Access displays category sample names along the top of the sample query preview at the bottom of the dialog box. Click Next to continue.
Select a field to display as row headings on the Crosstab query wizard.
If you choose a Date/Time field for column headings, the next page of the wizard asks you to specify the interval to use to group the dates. You can specify Year, Quarter, Month, Date, or Date/Time. If you do not choose a Date/Time field for column headings, the wizard skips this page.
On the next page, choose a field and a function to use to calculate summary values. The data type of the field that you select determines which functions are available.
On the same page, select or clear the Yes, include row sums check box to include or exclude row sums.
If you include row sums, the crosstab query has an additional row heading that uses the same field and function as the field value. Including a row sum inserts an additional column that summarizes the remaining columns. For example, if your crosstab query calculates average age by location and gender (with gender column headings), the additional column calculates the average age by location, across all genders.
For this example, select ID in the Fields box and Count in the Functions box in order to have Access count the number of products in each intersection of supplier and category. Leave the Yes, include row sums check box selected. Access will create a column that totals the number of products from each supplier. Click Next to continue.
Select a field and function to calculate on the Crosstab query wizard.
On the last page of the wizard, type a name for your query and then specify whether you want to view the results or modify the query design.
You can change the function that is used to produce row sums by editing the crosstab query in Design view.
If you've walked through this example using the Products table from the Northwind database, the crosstab query displays the list of supplier names as rows, the product category names as columns, and a count of the number of products in each intersection.
In your example, your data is completely different. In the first example, you have Name1, Name2, Name3, as field names and in the second example, you have Member1, Member2, Member3 as field names. Let's say this is your actual data.
id Number Name
3697 445923962 Member1
3696 445923962 Member1
3695 445458553 Member1
3696 445458543 Member2
3697 445458543 Member2
3695 445458543 Member2
3695 445458551 Member2
3695 445458560 Member3
3696 445458226 Member3
3697 445458226 Member3
Then, this is your SQL.
TRANSFORM First(Table1.[Number]) AS FirstOfNumber
SELECT Table1.[id], First(Table1.[Number]) AS [Total Of Number]
FROM Table1
GROUP BY Table1.[id]
PIVOT Table1.[Name];
This is the Design View.
When you run the SQL, you get this.
Make sense???
Hello i want to split a resulting column in multiple columns just like on the link. But number of columns are not specific ;
Example
COL1 | OTHER COLUMNS
----------------------------------------
this,will,split | some value
also,this | some value
this,is,four,columns | some value
I want make this something like that ;
COL1 | COL2 | COL3 | COL4 | OTHER
----------------------------------------
this | will | split| NULL | some value
also | this | NULL | NULL | some value
this | is | four | columns| some value
edit
it looks like similar that question but not:
Can you split/explode a field in a MySQL query?
I want results in 1 row, I dont want something like that;
RESULT
-----
this
will
split
...
on that question you can see there is specific number of cols. bu i dont. :(
How to split a resulting column in multiple columns
I think you can create one relational table and add multiple entry in relational table, hear you don't need to think about column, you have to add entry in row.
eg.
Table 1:
ID | COL1 | OTHER COLUMNS
----------------------------------------
1 |this,will,split | some value
2 |also,this | some value
3 |this,is,four,columns | some value
Table2
ID | Table1_id | value
-------------------------
1 | 1 | this
2 | 1 | will
3 | 1 | split
4 | 2 | also
5 | 2 | this
6 | 3 | this
6 | 3 | is
6 | 3 | four
6 | 3 | columns
Please check this, i think fix your problem.
I'm wondering how to filter Hibernate results.
For example, I have this example table:
--------------------------------------------
| ID | STRING | DATE |
--------------------------------------------
| 1 | "ABC" | 2014-11-07 21:45:00 |
--------------------------------------------
| 2 | "ABC" | 2014-11-07 22:45:00 |
--------------------------------------------
| 3 | "DCE" | 2014-11-07 22:48:00 |
--------------------------------------------
| 4 | "ABC" | 2014-11-07 23:48:00 |
--------------------------------------------
The result that I need is:
--------------------------------------------
| ID | STRING | DATE |
--------------------------------------------
| 3 | "DCE" | 2014-11-07 22:48:00 |
--------------------------------------------
| 4 | "ABC" | 2014-11-07 23:48:00 |
--------------------------------------------
All lines of table, BUT, when I have the same content in column STRING, the column with the most recent DATE is the one in result set.
In hibernate I know
- select ALL lines;
- select the repeated lines and keep only the most recent.
But I don't know how to combine the two situations together, and I can't find it referenced anywhere.
I have a fixed length in STRING, and I use a fake primary key in my code to identify the register, but the value is inserted by user, and I have no previous knowledge of the content in the column.
You can do this using a not exists clause:
select e.*
from example e
where not exists (select 1 from example e2 where e2.string = e.string and e2.date > e.date);
That is, select all rows where there is no other row with the same string and a larger date.
I have table:
+----+--------+----------+
| id | doc_id | next_req |
+----+--------+----------+
| 1 | 1 | 4 |
| 2 | 1 | 3 |
| 3 | 1 | 0 |
| 4 | 1 | 2 |
+----+--------+----------+
id - auto incerement primary key.
nex_req - represent an order of records. (next_req = id of record)
How can I build a SQL query get records in this order:
+----+--------+----------+
| id | doc_id | next_req |
+----+--------+----------+
| 1 | 1 | 4 |
| 4 | 1 | 2 |
| 2 | 1 | 3 |
| 3 | 1 | 0 |
+----+--------+----------+
Explains:
record1 with id=1 and next_req=4 means: next must be record4 with id=4 and next_req=2
record4 with id=5 and next_req=2 means: next must be record2 with id=2 and next_req=3
record2 with id=2 and next_req=3 means: next must be record3 with id=1 and next_req=0
record3 with id=3 and next_req=0: means that this is a last record
I need to store an order of records in table. It's important fo me.
If you can, change your table format. Rather than naming the next record, mark the records in order so you can use a natural SQL sort:
+----+--------+------+
| id | doc_id | sort |
+----+--------+------+
| 1 | 1 | 1 |
| 4 | 1 | 2 |
| 2 | 1 | 3 |
| 3 | 1 | 4 |
+----+--------+------+
Then you can even cluster-index on doc_id,sort for if you need to for performance issues. And honestly, if you need to re-order rows, it is not any more work than a linked-list like you were working with.
Am able to give you a solution in Oracle,
select id,doc_id,next_req from table2
start with id =
(select id from table2 where rowid=(select min(rowid) from table2))
connect by prior next_req=id
fiddle_demo
I'd suggest to modify your table and add another column OrderNumber, so eventually it would be easy to order by this column.
Though there may be problems with this approach:
1) You have existing table and need to set OrderNumber column values. I guess this part is easy. You can simply set initial zero values and add a CURSOR for example moving through your records and incrementing your order number value.
2) When new row appears in your table, you have to modify your OrderNumber, but here it depends on your particular situation. If you only need to add items to the end of the list then you can set your new value as MAX + 1. In another situation you may try writing TRIGGER on inserting new items and calling similar steps to point 1). This may cause very bad hit on performance, so you have to carefully investigate your architecture and maybe modify this unusual construction.
this is the query
select count(*),
ss.pname,
ttu.user_id,
ttl.location_name ,
group_concat(em.customer_id),
count(em.customer_id)
from seseal as ss,
track_and_trace_user as ttu,
track_and_trace_location as ttl,
eseal_mapping as em
where ss.real_id=em.e_id
and em.user_id=ttu.user_id
and ttu.location_id=ttl.location_id
group by ss.pname, ttu.user_id, ttl.location_name
having count(em.customer_id)>1 ;
and following is the results:
+----------+----------------+---------+---------------+------------------------------+-----------------------+
| count(*) | pname | user_id | location_name | group_concat(em.customer_id) | count(em.customer_id) |
+----------+----------------+---------+---------------+------------------------------+-----------------------+
| 6 | Nokia N91 | 1 | Malad | 60,51,60,51,58,58 | 6 |
| 2 | SUPERIA 1000gm | 4 | Raichur | 51,46 | 2 |
| 5 | SUPERIA 1000gm | 5 | west bengal | 51,46,51,51,46 | 5 |
| 2 | SUPERIA 500gm | 4 | Raichur | 59,59 | 2 |
| 3 | SUPERIA 500gm | 5 | west bengal | 59,46,59 | 3 |
+----------+----------------+---------+---------------+------------------------------+-----------------------+
Now the problem is, as you can see in result set, the second last column in some rows the customer_ids are duplicate and in some rows are unique. And the last column is giving the count of it.
Now what i want is to pick the 3rd row, there are two customer ids namely 51 and 46 and these are duplicate in that row, so my last column for this row should contain 2.
Similarly for last row my last column should contain 1 as there is only one customer id which is duplicated i.e. 59.
So if you understand the exact problem then the 2nd row should not be part of this result set as it doesn't contain any customer ids that are duplicate.
How about:
group_concat(distinct em.customer_id)
and
count(distinct em.customer_id)