score:0
Accepted answer
This should give you what you are looking for.
select distinct stock_yard_name, stock, sale
from (
select stock_yard_name , sum(stock_net_weight) stock
from table1
group by stock_yard_name) t1
join (
select sale_yard_name, sum( sale_net_weight) sale
from table2
group by sale_yard_name
) t2 on stock_yard_name = sale_yard_name
score:-1
select ref.stock_yard_name,ref.stock_net_weight as stock, ref.sale_net_weight as sale,
ref.stock_net_weight - ref.sale_net_weight as advance
from(
select st.stock_yard_name as stock_yard_name, sum(st.stock_net_weight) stock_net_weight, sa.sale_net_weight
from tbl_stock st
inner join
(
select sale_yard_name, sum(sale_net_weight) sale_net_weight
from tbl_sale
group by sale_yard_name
) sa on (st.stock_yard_name = sa.sale_yard_name)
group by st.stock_yard_name,sa.sale_net_weight
)ref
order by ref.stock_yard_name asc
More Answer
- Select from different table with different column in one query
- Update mysql table with one query the values from an automated generated form
- SQL query sums data from one col by distinct in another. Distincts stored in table as integers with name in another table. How do I output real name?
- Table from SQL query with header
- How to get data from two different table with different columns
- Using two values from different table as date range in query
- Sum and average multiple columns from different SQL tables with PHP/PDO
- Group and sum items from two arrays containing result sets with foreach
- How to group by HTML table different rows from MYSQL database
- How to access data from two different table within single model/controller/form in yii
- Propel returns different output for the same query with same table
- Access a Zend application from another computer in the LAN (working with LAMP)
- How to extract data from a table With no Style/Class/ID information
- How do I list data from a specific database table as a list with links?
- Get all data associated with an identifier from SQL table
- PHP SQL Order By from a field in a different table
- PHP Trying to get string from a table cell with regular expressions
- Zend Table Relationship with Primary Composite Key - delete record from table
- how to query db when user has more than one table associated with the results i want?
- Symfony - how to access table data from link table
- How to create excel table from parent-child table with php?
- PHP - merge values from array with same key and different values
- I couldnt get datas from each html table which returns with PHP
- How to populate an html table with data from an array in php
- Organise fetched images links from MySQL table in 3 different div by php
- How can put my values to mysql from my php table with jquery ajax method
- Query with data from user in MSSQL with PHP
- How can I update a table data (td) with respect to another table data of a different column
- Laravel Eloquent query with condition and using sum and groupBy
- Join one complete table and one column from another table inside the same database and display with PHP
- Laravel Cart Sum based on input from 2 different tables
- Trying to access data returned from Stripe API with Alamofire, but result is not valid JSON
- Silverstripe 4 - How to query for getting all data from table and add field to cmsField
- php - how to calculate percentage with scale different from 0-100?
- Save the query result from a table into a variable then send it into another table
- Delete a table row with dynamic id that comes from DB using ajax
- Correctly storing query response with GROUP BY using PHP
- Get value from table with jquery
- How to replace preg named group with values from array with corresponding keys?
- Passing function that needs to display a table from the database with a foreach loop PHP
- How to add button to a JavaScript based Table with Data from PHP Database?
- how to combine 2 columns from different tables into 1 column in 1 table in laravel
- How to Create multiple table from query based on multidimensional array
- How to run a function onClick with different values from PHP <li>'s?
- Problem with deleting items from pivot table
- Couldn´t access the designated node with cascaded xpath query
- How do I call different values of each columns in my Mysql table with same invoice nº?
- Populating HTML table from 2 different Array in PHP
- Create HTML table with header row and potentially missing cell values from array of associative arrays
- want to connect to the same database table but with different values
More answer with same ag
- "Body Onload" to send "ScrollHeight" not working properly in Chrome and Safari
- Arduino can't POST data to PHP
- Sending an email after form submission
- How to link a href with javascript
- FPdf - echo input into table header
- variable returns the word ARRAY in session
- filtering out elements in string PHP
- Best approach for styling SilverStripe's Blog module
- Venmo - Braintree payment - Server Integration
- Replace Local Links, Keep External Links
- Explode string then parse delimiter for a variable
- Raspberry PI: Turning LED On/OFF via server
- Loading a JSON file javascript
- TABLE.label doesnt exist YII, framework
- Why are users who do not exist allowed to login using this bit of script?
- Escape a valid filename/path
- CakePHP magic findBy method for comparisons
- How to match div content which has divs inside by using regex
- Learning PHP connect script shows constants using httpsfox
- returning results with Json_encode
- How to set up a contact form?
- PHP Reconstruct Array
- PHP Search and check for value in Array Object
- PHP - Go back to previous URL after login with Facebook
- Symfony not load translation
- Scenario not working on form validation with Yii 2
- Combobox onchange event to select database values
- Print Barcode from ID database
- PHP Multiple File Upload show each file name
- A3M auth for an already existing site
- preg_replace with lots of special characters
- php output system() in real time
- Serializing objects with relationships to ZF3 MVC Response JSON
- Zend framework with default and mobile layout
- How to send Push Notifications using php in flutter App?
- need to update some text into website developed with twig silex symfony
- Sending Mail automatically at a particular time?
- PHP submit to self form
- How to check in PHP that any values exist in array in addition to some fixed value
- HASH for GIF IMAGES
- Undefined variable, can't declare variable?
- PHP Retrieve all users Google Directory Admin SDK
- Creating a jQuery event handler that initiates PHP code
- Perl CGI script pass request to PHP
- Php: Reading $_POST-array with filter_input returns empty array
- Datatable Manual Search with Ajax
- removing element from a composite / array (composite pattern)
- foreach loop through multidimensional array and only echo arrays containing specific value
- php add to cart not adding more than 2 products
- Receive users Hostname in Php Contact Form
Source:
stackoverflow.com