last day (15 days later) » 

2:26 PM
0
Q: how create a ' one to many ' sql query statement

Rodney Narti have a table called(center_info) which which has a student's information and their total bills paid and total balance remained. and another table called (center_payments) which has records of each single date of bill paid by a student. I want to join records of a student in table 1(center_info)...

 
please all help will be appreciated. thank you !
 
I'm not really sure what you need, are you having problem creating the sql to group them?, are you having issues with how to structure the report?, what does link records of students mean, do you want it to be "clickable"?.
 
@ Petter Friberg, I want an sql query to group records which have similar id and share the same column value(term=1). please that's what I meant by linking the records of students bro
 
I think you should rewrite the question, if you need to understand the sql to execute focus only on that.. show tables, some sample data and desired output. Currently you have too much stuff in this question (leave all the jasper reports stuff out).
 
ok bro. and I will appreciate it if you can write the sql query for me please
 
2:26 PM
Have you checked this stackoverflow.com/q/6105767/5292302, it seems like a straight forward sum, max, group by query.
 
thank you @Petter Friberg. but what I want is a one to many relationship sql query.
 
still it's same thing, start to select all the fields you like (with the join query and where), then check what to group on (id), then sum (paid) and max(date) the fields as you need.
 
I wrote this ``` select a.id,a.student,a.bill,a.term,a.total_paid,a.total_balance, a.last_date_of_pymt,b.paid,b.balance,b.date from center_info a INNER JOIN center_payments b using(id) group by a.id having a.term='1'``` but it doesn't seem to work @Petter Friberg. kindly help
 
Does not work?, error executing it??, then I don't see any sum or max in your query...
 
@Petter Friberg, for now I just want to join the records from the two tables with similar ids where term=1. am just frustrated already!
 
2:26 PM
remove the group by, remove having use where instead and check if you get the records you need.
 
``` select a.id,a.student,a.bill,a.term,a.total_paid,a.total_balance, a.last_date_of_pymt,b.paid,b.balance,b.date from center_info a INNER JOIN center_payments b using(id) where a.term='1'``` this is even worse.it displays all records from the second table and attaches it to the first table. hmmm
 
Perfect we want that :D
Now switch b.paid to sum(b.paid) as totalPaid and group by b.id at the end
check if you get atleast the total paid correct, then add sum and max to other fields as you ned
 
thank you for your time bro
so please any other ideas
 
any other ideas?... did it not work?
 
2:42 PM
no bro, am thinking the core problem is from the jasper app...
because the syntax seem to be ok but jasper just cant seem to display it the want the results to appear
 

last day (15 days later) »