How to use alias in group by clause in php using mysql

In last tutorial, we have had a glimpse about how to use Group By clause. Rows in a table can be grouped by using one or more columns. For example, rows in products table can be grouped by CategoryID values so that we can see summarized information for each group of the product categories (e.g. what is the total number of units in stock for each product category). When using Group By clause, consider the following facts and guidelines.

SELECT tbltai_sales.*, count(tbltai_sales.sales_id) as qty, 
sum(tbltai_sales.grand_amount) as totalprice, 
(SELECT tbltai_sales_items.brand_id FROM tbltai_sales_items WHERE
 tbltai_sales_items.sales_id=tbltai_sales.sales_id group by tbltai_sales_items.sales_id) 
AS finalbrandid 
 FROM tbltai_sales WHERE tbltai_sales.issue_date = '2017-05-05' group by finalbrandid 

Leave a Reply

Your email address will not be published. Required fields are marked *