how to sum of records - visual-studio-2010

i have table in which there no. of transactions in many accounts .... how to sum of all transaction according to account wise....as well as i want to display sum of all transactions account num wise of all account number
for ex..
account_num transaction_amt
001 200
001 300
002 330
002 400
and so on
i want to display as
account_num total_transaction
001 500
002 730
and so on
please help me out

SELECT account_num, sum(transaction_amt) as total_transaction
FROM mytable
GROUP BY account_num
Then press F1 and look at the help under 'SQL-Select'.

Related

How to count one column when another column is distinct (Oracle BIEE)

I want to have a new column showing how many orders that I have for the shipment.
How can I do that in obiee
Example Table:
Shipment
Order
Order Quantity
125
001
3
125
002
3
125
003
3
126
004
2
126
005
2
I can't have a new column with order quantity for each shipment
Add a sum for the "Shipment" attribute to the visualization and the tool does it automatically. Or create a measure using SUM("Order Quantity" by "Shipment") which you can then use to cross-calculate

How to sum two column from different Table in H2 Database

I have two tables in database called purchase AND sales
Tables as follow
Table purchases
----------------------------
ID PRODUCT QTY
----------------------------
1 APPLE 100
2 BANANA 200
3 GRAPES 150
4 AVACADO 110
Table Sales
----------------------------
ID PRODUCT QTY
----------------------------
1 APPLE 50
2 BANANA 200
3 GRAPES 100
Here in the above tables i have purchase and sales i want to do subtraction from purchases quantity with sales quantity
and get the output like this
Output
----------------------------
ID PRODUCT QTY
----------------------------
1 APPLE 50
2 BANANA 0
3 GRAPES 50
4 AVACADO 110
i written query but not working
select id, product, (purchases.qty)-(sales.qty) from purchases left join sales on purchases.id=sales.id
Solution
SELECT purchases.id,purchases.product, (purchases.qty - IF (sales.qty IS NULL, 0, sales.qty)) as qty FROM pruchases LEFT JOIN sales ON purchases.product = sales.product
See all three Images your problem may be solved.
SALES TABLE [Same as Sales Table]1
PURCHASE TABLE [Same as Purchase Table]2
RESULTANT IMAGE [Resultant Image With Query]3

Tables Summary into single table in laravel

I have two tables named 'Customers' and 'Committeetables' in mysql database. They have following columns
Table: Customer
nd Name FatherName Cell# AdvanceAmount
25 Waseem Asghar 0302 2500
30 Ramzan Khan 0303 3500
35 Rana Ali 0307 2000
Table: CommitteeTables
nd Amount RecievingDate DrawDate
25 1500 2-10-15 10-10-15
30 1500 2-10-15 10-10-15
25 1500 3-10-15 10-11-15
30 1500 3-10-15 10-11-15
35 1500 3-10-15 10-11-15
A Column 'nd' in 'Customers' table is primary key and in 'CommitteeTables' table is foreign key. It means 'Customers' table joins with 'ComitteeTables' table through 'nd' column.
Expected Result table should be as under:
nd Name Father Name Cell# Advance Amount Balance
25 Waseem Asghar 0302 25000 3000 22000
30 Ramzan Khan 0303 35000 3000 32000
32 Rana Ali 0307 20000 1500 18500
----------------------------------------------------------------------------
total 80000 7500 72500
I am using Laravel 5 and HTML, Bootstrap. I need this result in Laravel 5. I shall be really thankful if someone help me to solve my problem.
Thanks
Waseem
This is not at all a Laravel question. It's a general SQL question.
Something like this:
SELECT nd, Name, FatherName, Cell#, AdvanceAmount as Advance,
(SELECT SUM(Amount) FROM CommitteeTables WHERE CommitteeTables.nd=Custoemr.nd) as Amount, Advance-Balance AS Balance
FROM Customer;
I'm not entirely sure that's correct but you can try it and fix any errors. As Bogdan suggests you should try something first then come back here with any problems that you have.

oracle query to display the similar value rows at last..?

I need to display the similar values rows of the table at last while the remaining rows of the table has to come in ascending order...
for ex:
Name salary
---------------------
a 100
b 200
c 300
c 400
c 600
d 200
e 500
I need the output as ,
Name salary
-----------------------
a 100
b 200
d 200
e 500-----------------till here it has to come in ascending order ignoring 'c'
c 300
c 400
c 600
You can use the below query and modify it accordingly
select name,salary,(select count(name) from table_name where name=a.name) count_nm from table_name a order by count_nm,salary;
Hope this helps!

How to group by a column and show as one row

I have a table with following structure
SubId Status
---------------------------------------
001 Active
001 Partially Active
While displaying this record, I need to display this like this
SubId Status
---------------------------------------
001 Active/Partially active
I tried using distinct, but this returns both rows.
Any idea how can I get only 1 row instead of 2. I know it would be simple. I just cannot find it.
select subid,
listagg(status, '/') within group (order by null) as status
from the_table
group by subid;

Resources