php - how to put GROUP BY correctly? -


How to properly categorize this query:

  $ sQuery = "SELECT id , Date (A inspection_data) AS Date, A. Model, Number (A.Seal_Number) AS Qty, BNA Inspection as an Appointed Employee, as a designated employee, BA NIK = B. NIC Date by date, B. $ sWhere $ sOrder $ sLimit ..  

I'm really new in the inclusion.

you need By both the 'ID' and 'A model' group, at least most of the SQL DBMS (MySQL has unstable rules in this area). You have to go after the WHERE clause and come after the order buy clause. Therefore:

  $ sGroupBy = "id, date, a by group. Model, b.name "; $ SQuery =" SELECT id, DATE (A.Inspection_datetime) AS Date, A.Model, COUNT (A.Serial_number) AS Quantity, BNN.N.K.K. As BEF . $ Swhere $ sGroupBy $ sOrder $ sLimit ...  

Note that you must ensure that there are spaces to separate the different sections that you meet together;

$ sGroupBy (and thereafter B.NIK ). >

Comments