DB::raw query issue SQLSTATE[42000]: Syntax error or access violation: 1064

157
December 26, 2017, at 7:09 PM
DB::raw("SELECT  'finacial_calender.id' FROM 'finacial_calender' where 'finacial_calender.F_YEAR' = 'YEAR(invoice.INV_DT)' and 'finacial_calender.F_MONTH' = 'MONTH(invoice.INV_DT)'  ")

this line has an issue but my complete query is

$invoice_FlagS = DB::table('invoice')
            ->join('customer', 'invoice.CUST_ID', '=', 'customer.CUST_ID')
        ->join('cmp_dsr_products', 'invoice.DSR_PROD_ID', '=', 'cmp_dsr_products.DSR_PROD_ID')
        ->join('distributor_brick', 'customer.DSR_BRICK_ID', '=', 'distributor_brick.DSR_BRICK_ID')
        ->join('head_office_brick', 'distributor_brick.HO_BRICK_ID', '=', 'head_office_brick.HO_BRICK_ID')
        ->join('territory_division', 'head_office_brick.HO_BRICK_ID', '=', 'territory_division.HO_BRICK_ID')
        ->join('master_territory', 'territory_division.TERRITORY_ID', '=', 'master_territory.TERRITORY_ID')
        ->join('districts', 'master_territory.DISTRICT_ID', '=', 'districts.DISTRICT_ID')
        ->where('invoice.COMPANY_ID', '=', $company_id)
        ->whereBetween('INV_DT', [$fromDate, $toDate])
        ->select('master_territory.TERRITORY_ID','master_territory.DIV_ID','master_territory.DISTRICT_ID','districts.REGION_ID','cmp_dsr_products.PROD_ID','invoice.INV_QTY','invoice.INV_DISCOUNT_VAL','invoice.INV_NET_VAL','invoice.INV_DT','invoice.COMPANY_ID',DB::raw("SUM( ( CASE WHEN invoice.FLAG ='S' THEN invoice.INV_NET_VAL END ) ) AS SaleAmount"),DB::raw("SUM(abs( ( CASE WHEN invoice.FLAG ='R' THEN invoice.INV_NET_VAL END )) ) AS ReturnAmount"),DB::raw('MONTH(invoice.INV_DT)'),DB::raw("SELECT  'finacial_calender.id' FROM 'finacial_calender' where 'finacial_calender.F_YEAR' = 'YEAR(invoice.INV_DT)' and 'finacial_calender.F_MONTH' = 'MONTH(invoice.INV_DT)'  "))
//      ->select('distributor_product.DSR_PRODUCT_NAME','INV_ID','INV_QTY','INV_DISCOUNT_VAL',DB::raw('sum(INV_NET_VAL)AS SaleValue'))
        ->orderBy('invoice.INV_DT', 'asc')
        ->groupBy('invoice.INV_DT','invoice.DSR_PROD_ID')
        ->get();
READ ALSO
mySQL table loses column structure when exported as CSV format

mySQL table loses column structure when exported as CSV format

I am trying to export a table from MariaDB to a folder in CSV formatIn MariaDB program, I entered the query: MariaDB [testdatabase]> SELECT * from datatable into outfile '/tmp/exportf

153
Mysql - select random 4 data from a column, distinct by 2 different columns

Mysql - select random 4 data from a column, distinct by 2 different columns

I'm trying to select 4 different random data from a table on Mysql but I want some fields unique, for example;

139
Disable PAY Button when status “paid”

Disable PAY Button when status “paid”

I want to disable pay button when status paid

140
MySQL Select the field as Distinct having data type as Text with filtering

MySQL Select the field as Distinct having data type as Text with filtering

If we have a table T1 with a field named orders have data type as Text

128