Sum and Difference of columns in Ms-Acess in Two different tables - ms-access

Table : StudentTuitionFee
GradeLevel TuitionFee MiscFee RegistrationFee BooksFee
Grade 1 25,000.00 5,000.00 3,000.00 3,500.00
Table : StudentRegistration
Gradelevel StudentID
Grade 1 50090
Table : Student Profile
StudentID Name
50090 Oliver
Table : Payment
StudentID OR# TuitionPay MiscFeePay RegistrationFeePay BookFeepay
50090 1 5,000.00 500.00 500.00 500.00
50090 2 5,000.00 500.00 500.00 500.00
I'm creating a form that will show the data using the student id which I already able to show in the forms.
My Question is how to calculate the Difference from the StudentTuitionFee table and the Payment table. Using only the StudentID 50090.
The difference of TuitionFee, MiscFee, RegistrationFee and BookFee against all payments done in Payment table on TuitionFeepay, MiscFeePay, RegistrationFeePay and BookFeepay.

Related

Define table of choosed user row in multiple table list

I have control dashboard where multiple tables are listed with query
And in dashboard I can switch it to one table from ALLData to User1Table... and vice versa.
When there is only one table chosed I can easily manipulate data. However, I am struggling with updating rows when ALLData(all tables) are listed in dashboard. I can update it checking each table. I was wondering is there any better way to update it.
Tables have no DR. All tables have same column names.
//ALLData
SELECT * FROM users1
UNION ALL
SELECT * FROM users2...
user1
id name tel status
1 Bob 911 1
user2
id name tel status
3 Anna 11 0
3 Jack 12 1
//ALLData in dashboard
id name tel status
1 Bob 911 1
3 Anna 11 0
3 Jack 12 1
I can use id and status as PK

SQL difficult statement

Currently I'm looking for a solution. English is not my native language so I added two pictures to clarify it a bit. My knowledge of SQL is rather basic.
A chair (end-product) contains several components. Each component contains an item number, each spare set contains multiple item numbers. In the database a spare set is in the same table as an end-product. The chairs and spare parts are categorized in different groups.
Is it possible to create a table like that? If it's possible how?
Thanks in advance!
This would be my approach:
Table: Products -- a table of products
ProductID ProductName DateAdded
1 Chair X 01/01/2016
2 Chair Y 05/05/2016
3 Spare Set A 06/06/2016
...
Table: Components -- a table of components
ComponentID ComponentName ItemNumber DateAdded
1 Backrest X01 01/01/2016
2 Headrest X02 01/01/2016
...
Table: ProductComponent -- a lookup/mapping table to link Product and Component
PCID ComponentID ProductID DateAdded
1 1 1 01/01/2016
2 2 1 01/01/2016
...
DateAdded is the date the product or component was first entered into the database. It is for audit purposes.

Join multiple table and sort the result

This is the first question i post in stackoverflow. Hope that you guys can help me resolve this problem. I have been stuck for 2 days.
I have 6 tables. It's all below:
students:
id name lastname
1 John Snow
2 Sansa Stark
3 T-Bag Bagwell
student_course:
id student_id course_id course_start course_end
1 1 1 2015-06-19 2015-08-20
2 2 3 2015-07-09 2015-09-15
3 3 1 2015-05-15 2015-08-22
payment:
payment_id student_id course_id
1 1 1
2 2 3
3 3 1
payment_initial:
payment_id payment_due
1 2015-06-12
3 2015-05-08
payment_installment:
payment_id payment_due int_payment_due
2 2015-07-02 2015-07-15
passport_visa:
student_id passport_expiry_date visa_expiry_date
1 2015-09-10 2015-10-12
2 2015-09-12 2015-09-15
3 2015-10-11 2015-9-28
And the result i want is: result will be sort by date combined form 3 tables which have "Date" field. "Date" field after sorting include only date after present.
How can I make query string that bring me the result like this:
student_id(1) course_id(1) course_start(2015-06-19)
student_id(2) course_id(3) payment_id(2) payment_due(2015-07-02)
student_id(2) course_id(3) course_start(2015-07-09)
student_id(2) course_id(3) payment_id(2) int_payment_due(2015-07-15)
student_id(1) course_id(1) course_end(2015-08-20)
student_id(3) course_id(1) course_end(2015-08-22)
student_id(3) passport_expiry_date(2015-09-12)
.....
I want to add Name and Lastname at the result but it show too long. So I just write like that.
Last result i want to get is the date field (sorted), and which event of date will happen (course start, course end, payment due...)
Sorry if my English grammar is bad. Please help me. Thank you all.
I just collect all result after insert data (which has date field) into one table, and sort them in that table. That makes more insert query but easy to sort.
So I do it on that way.

How to query that will display the balance deducted from column B to column A in MySQL database

I have a table named cdr_records with this columns :
TABLE: CDR_RECORDS
------------------
CDR_ID DATE CHECK_NO NAME_OF_PAYEE CHECKS_ISSUED
1 2014-01-01 3456111 John Smith 1,830.96
2 2014-01-01 3456112 Chen Lee 90,048.92
3 2014-01-01 3456113 Hen Lu 22,740.75
and I created another table that records all the data for the NCA (Notice of Cash Allocation) receive to be allocated to each check issuances.
TABLE: NCA
----------
NCA_DATE NCA_RECEIVED
2014-01-01 7,257,000.00
2014-01-01 5,564,000.00
using the query, SELECT SUM(NCA_RECEIVED) would result 12,821,000
I want to display the BANK_BALANCE of each records of check issuance by subtracting the
sum of 12,821,000 to each check issuances to obtain the balance as follows:
12,821,000 - 1,830 = 12,819,170
12,819,170 - 90,048.92 = 12,729,121.08
and so on illustrated below.
CDR_ID DATE CHECK_NO NAME_OF_PAYEE CHECKS_ISSUED BANK_BALANCE
1 2014-01-01 3456111 John Smith 1,830.96 12,819,170.00
2 2014-01-01 3456112 Chen Lee 90,048.92 12,729,121.08
3 2014-01-01 3456113 Hen Lu 22,740.75 12,706,380.33
Can anyone help me how to query to obtain the running balance deducted to each check issuances?
Any help would be great appreciated.. thanks
Thanks for the answer and it really solved on how to display the running balance..
But another problem is that I store the data from different tables with foreign keys as follows :
Table: issue_details
issue_id (PK) issue_date check_no issue_amount
1 2014-01-01 345611 1,500.00
2 2014-01-01 345612 21,000.12
Table: cdr_records
cdr_id (PK) issue_id (FK)
1 1
2 2
Table: nca
nca_no (PK) nca_date nca_received
111 2014-01-01 7,257,000.00
112 2014-01-01 5,564,000.00
Im new to sql and Im not good at joining tables when performing calculations. How to perform the same calculation but of relational tables ?
You can do this with variables. The key is initializing the total to the value from the `nca table.
select r.*,
(#tot := #tot - checks_issued) as bank_balance
from (select #tot := sum(nca_received) as nca
from nca
) vars cross join
cdr_records r
order by r.date, r.check_no;

mySql - Best way to model price discount table for bulk purchases - Recursion?

Building an eCommerce store, and wish to offer pricing discounts for bulk orders. Each product may have different discount tiers.
e.g. different % discounts dependent on qty ordered.
Product : Quantity Bands[discount]
Product A: 1-10[0%], 11-20[5%], 21-50[15%], 51+[20%]
Product B: 1-5[0%], 6-10[10%], 10+[30%]
Product C: 1-10[0%], 11-20[5%], 21-50[15%], 51+[20%]
Bit confused as to how I should model this in a database...
My initial thoughts were to model my discounts table as a self refrencing adjacency list. The product table would have a discount_id to determine which discount band it belonged to.
e.g.
discounts table:
id int
name string
discount decimal
parent_id int nullable
sample data:
id name discount child_id
=============================================
1 1-10 0 2
2 11-20 0.05 3
3 21-50 0.15 4
4 51+ 0.20 null
=============================================
5 1-5 0 6
6 6-10 0.10 7
7 10+ 0.30 null
=============================================
products table
id int
name string
base_price decimal
discount_id
so in the products table, a product can have a discount_id of either 1 or 5. Lets assume discount_id is 5. So to get a table showing prices and discounts for bulk purchases, I recursively loop through the discount_id's starting from 5 until child_id is null?
Am I completely off the mark or is there a better way of modelling this data?
you need a table with 4 fields
id
product_id
tier
discount
e.g.
1 1 1 0
2 1 11 5
3 1 21 15
4 1 51 20
and simply join your products table with the order table and the discounts table to figure out the discount to apply for that product