SUM returns Wrong result [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I have a table that lists the materials used to make the product. and I retrieve the prices times the quantities, then sum the results to determine the costing.
I created a SQL statement that uses SUM(td price*td current quantity). However, the outcome was incorrect.
function row_data($row_id){
$this->db->select('*,SUM(transfer_details.td_price * transfer_details.td_current_qty) AS total,trim(GROUP_CONCAT(DISTINCT stock_details.sd_wh_id SEPARATOR ",")) as whs');
$this->db->from('manufacturing_workshops');
$this->db->join('transfer_details','transfer_details.td_th_id = manufacturing_workshops.mw_transfer_id','left');
$this->db->join('maintenance_details','maintenance_details.md_id = manufacturing_workshops.mw_md_id');
$this->db->join('stock_items','stock_items.s_id = manufacturing_workshops.mw_si_id');
$this->db->join('stock_details', 'stock_details.sd_si_id=stock_items.s_id');
$this->db->where('mw_id',$row_id);
$this->db->group_by('transfer_details.td_id');
$data = $this->db->get();
return $data->result();
}
I need to return the sum of the multiplication of the td_price and td_current_qty columns.

Related

how to find name john and replace with smith in Laravel from name column of a table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
My String from name Column
john_items.3
I want to fetch all these names that start with the john and replace all of them with smith and update columns like
**john_items.3**
will become
**smith_items.3**
$replacedItems = \App\Models\ModelName::where('name', 'LIKE','john'.'%' )
->get()
->map(function ($item) {
$item->name = str_replace('john', 'smith', $item->name);
$item->save();
return $item;
});
// Print all
dd($replacedItems->toArray());

Display subcategory in main category in laravel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
$cat = Category::all();
$sub = Subcategory::all();
return response(['cat' => $cat, 'sub' => $sub]);
you need to prepare your data to be easy to loop on it so you can get category with each related subcategory like this :-
$cat = Category::with('subCategory')->get();
so you need to add this relationship inside category model .
in this point you will get the categories with each category you will have its related sub category .

convert date to timestamp in yii2? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
$date = Yii::$app->request->post('date');
$timestamp = strtotime($date);
var_dump($timestamp );
error
PHP Warning – yii\base\ErrorException
strtotime() expects parameter 1 to be string, array given
you should check you post for an array in $_POST('date')
in this case you could access at the value providing an index
$timestamp = strtotime($date[0]);

How can i get this SQL on yii2? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am working with Yii2 and I need to use the Query Builder to convert the following raw SQL query where I am using a subquery in the inner join.
SELECT *
FROM class
INNER JOIN
(SELECT name, MAX(score) AS Maxscore
FROM class
GROUP BY name) topscore
ON class.name = topscore.name
AND class.score = topscore.maxscore;
You should show a bit of effort on your behalf as it is how it works here on SO, but as you are a new bee so i am adding an answer.
It is pretty straight forward see the Query builder guide, and you need to use the subquery in the following way
$subQuery = new \yii\db\Query();
$subQuery->select([new \yii\db\Expression('[[name]], MAX([[score]]) as Maxscore')])
->from('class')
->groupBy('[[name]]');
$query = new \yii\db\Query();
$query->select('*')
->from('class')
->innerJoin(['topscore'=>$subQuery])
->where(['=','class.[[name]]',new \yii\db\Expression('topscore.[[name]]')])
->andWhere(['=','class.[[score]]',new \yii\db\Expression('topscore.[[maxscore]]')])
->all();
Note: I didn't tested it thou but it should work correctly.

meaning of a large mysql command [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can anyone help by describing this php mysql command please:-
SELECT itm.*,mem.username as username,cpn.*
FROM aw_rdw_items itm,members mem,aw_rdw_items_coupons cpn
WHERE itm.item_id=cpn.item_id
and item_special_type != 'g'
and itm.item_id=cpn.item_id
and itm.memberid=mem.memberid
and item like('%".addslashes($_REQUEST["item_name"])."%')
$prs1 $prs2 $greenget $subsql
ORDER BY Display_Order,itm.item_id ASC
SELECT
itm.*, // all columns of table itm
mem.username as username, // column username and assign the values to a variable called username
cpn.* // columns of table con
FROM aw_rdw_items itm, members mem, aw_rdw_items_coupons, cpn // tables where execute the research
WHERE itm.item_id=cpn.item_id // various conditions
and item_special_type != 'g'
and itm.item_id=cpn.item_id
and itm.memberid=mem.memberid
and item like('%".addslashes($_REQUEST["item_name"])."%') // item must contain the specified variable
$prs1 $prs2 $greenget $subsql // some php variables
ORDER BY Display_Order, itm.item_id ASC // order by Dispay_Order and itm.item_id in ascendant mode
Return all records who item_special_type is different from "g" and item contains value from item_name request value.
Where clause has another conditions that contained at $prs1, $prs2, $greenget and $subsql variables.