0
我得到這個還給我:獲取對象的屬性值了JSON
{
"GROUP_CONCAT(DISTINCT(CONCAT(\"MAX(IF(pa.printer = \"\"\", printer, \"\"\", pa.printer, NULL)) AS \", printer)))":
"MAX(IF(pa.printer = \"JP4-3\", pa.printer, NULL)) AS JP4-3,MAX(IF(pa.printer = \"JP4-1\", pa.printer, NULL)) AS JP4-1,MAX(IF(pa.printer = \"JP4-2\", pa.printer, NULL)) AS JP4-2,MAX(IF(pa.printer = \"B3\", pa.printer, NULL)) AS B3,MAX(IF(pa.printer = \"A2\", pa.printer, NULL)) AS A2"
}
我想要得到的這個值只是字符串。我無法從{}中取出。這應該是如此簡單,但無法在任何地方找到答案。
以下僅僅是引用我在做什麼
主要目標是MySQL的數據透視表。打2個電話,但我確定。
$listQuery = PrintJob::select(DB::raw('GROUP_CONCAT(DISTINCT(CONCAT("MAX(IF(pa.printer = """, printer, """, pa.printer, NULL)) AS ", printer)))'))->get();
這將返回上面的結果:
$json = $listQuery[0];
然後要在此查詢
$data = PrintJob::select(DB::raw('DATE(calendar.datefield) as date'), DB::raw('SUM(print_jobs.quantity) as sum'), DB::raw($listQuery))
->leftJoin('mo_numbers', 'mo_numbers.mo_id', '=', 'print_jobs.mo_id')
->rightJoin('calendar', 'calendar.datefield', '=', 'print_jobs.job_date')
->whereDate('calendar.datefield', '>=', date($from))
->whereDate('calendar.datefield', '<=', date($to))
->groupBy('date')
->toSql();
//->get();
你說的只是字符串是什麼意思? – AbraCadaver
之後的值: – BrinkDaDrink
我將字符串值移到了第二行以使其更清晰 – BrinkDaDrink