I have a dbmap which holds the database data
List<Long,List<validitycommerce>> dbmap= new HashMap<Long,List<ValidityCommerceregion>>
ValidityCommerceRegion contains
Validity id,
commerce id,
region id,
Now I have incoming list coming commerce id and region id say 151 be and 17 lu and I found the validityid of both 151 and 17 and I got the list of validityid's
Now I want to find the common validityid in both 151 BE and 17 LU
How can we achieve this?
Related
Let's say I have a very simple table called test:
ID AGE NAME
1 12 Bob
1 13 Bob
2 13 John
3 9 Michael
3 11 Michael
I want to return all results that have the largest AGE in the table. So for this case, the result would be the entities with the age 13:
ID AGE NAME
1 13 Bob
2 13 John
I would think something like this should exist, my thought process would have been the following (even though I know the syntax would not work):
connection.getSqlQuery()
.from(test)
.max(test.age)
.list(test.id, test.age, test.name);
What would be the proper query for this?
You can create a subquery and use it in your where clause:
// Aggregate to get the maximum age
var subQuery = connection.getSqlQuery()
.select(test.age.max())
.from(test);
connection.getSqlQuery()
.from(test)
.where(test.age.eq(subQuery))
.list(test.id, test.age, test.name);
If you use JPA, you can also use var subQuery = JPAExpressions.select(...
i am trying to new cache configuration with new DB tables. following are sample table structure and sample Data.
TABLE_DEPT:
Dept Id Detp Name Dept Dtls
111 SALES A1
112 MARKET A2
TABLE_EMP:
Emp Id Emp Name DeptId Working Started Working ended
1 ABEmp 111 01-01-2017 02-02-2017
2 CDEmp 112 01-01-2017 03-12-2017
3 EFEmp 113 01-01-2017 03-12-2017
1 ABEmp 115 03-02-2017 03-12-2017
if i want to add load the data in cache by using Dept Id, i will have unique dept Id with list of emp Id - details.
if i want to search by dept id in ehcache configuration, i can simply give search attribute is "dept id".
but, if i want to search by emp id, i should get list of dept under employee worked.
what should be my ehcache design?
my Java bean/POJO looks like below.
Class DeptDtls{
int deptId;
String deptName;
List<Integer> empIdList;
//Setter & getters
}
cache - i want to put key as deptId & value is whole DeptDtls.
in this case, how can i allow search operation based on empId?
Ehcache can provide in memory data storage only but in your case search also required on top cache.I got the same scenario and used elasticsearch for caching the data and search on stored data.elastic search has inbuilt support for search and we can index the stored data .elasticsearch can be configured for cache.
Please Help, I just can't figure it out.
I am trying to merge CSV rows together that have the same ID number, but have different values in the fields.
Please i dont have code.
For example,
Read in this CSV file:
ID NAME PHONE EMAIL
22 John 555-1111 john#aol.com
22 John 555-2222 john#aol.com
44 Bill 555-9999 Bill#aol.com
Should return:
ID NAME PHONE EMAIL PHONE0
22 John 555-1111 john#aol.com 555-2222
44 Bill 555-9999 Bill#aol.com
Thanks
I've not much experience in sql.In my little java program using ucanaccess library I was able to perform some simple queries after creating a simple table (named ReportSales). The table is:
ID DATE PRODUCT SALES FEES
1 2014-10-02 productA 10.000 100
2 2014-09-02 productC 12.000 240
3 2014-09-02 productA 8.000 80
4 2014-11-02 productB 7.000 105
5 2014-08-02 productB 6.000 90
.. .......... ........ ...... ....
.. .......... ........ ...... ....
The last task is to create a pivot table in which I would insert the monthly sales per product. Something like:
PRODUCT AUG SEP OCT NOV
productA 0 8.000 10.000 0
productB 6000 0 0 7000
productC 0 12.000 0 0
And another pivot for monthly fees
My (wrong) attempt is:
SELECT [8] as AUG, [9] as SEP, [10] as OCT, [11] as NOV
FROM
(SELECT SALES,MONTH(DATE)
FROM ReportSales) AS tmp
PIVOT
(
SUM(SALES)
FOR MONTH(DATE) IN ([8], [9], [10], [11])
) AS PivotTable
Does anyone can help me? Thanks in advance
UCanAccess supports Pivot queries, only if they are built in Access, so you have firstly to create a crosstab query using the Access IDE.
Or you may simply create a new query in Access entering directly the following SQL:
TRANSFORM sum(ReportSales.sales) AS SalesCount
SELECT ReportSales.product
FROM ReportSales
GROUP BY ReportSales.product
PIVOT Format([date],"mmm");
Then assuming that you saved the query as query1, you have just to execute, with UCanAccess:
Select * from query1;
Suppose i have a table Student
- ID Name Sub1 Sub2
- 1 Deepika 99 89
- 2 Shubham 78 90
I want my hibernate application to provide me the following result
- ID Name Sub1 Sub2 Total
- 1 Deepika 90 80 170
- 2 Shubham 78 90 168
i.e my sql query is
select id name, sub1, sub2, sub1+sub2 as total
from employee
How can i do this in Hibernate? What changes should i make in my hbm.xml file and bean class?
Using addScalar() you can fetch any additional row than the existing information without changing the xml. For more details refer this documentation
Otherwise you need to change the xml and bean class corresponding to the new table structure.