这是我的sql ..当我将它运行到 phpmyadmin 时,它运行正常。但是当我要以 DB:raw in laravel5.5 运行时,它会显示错误。在这里,奥克兰不是列名。
$ result = DB :: select("选择DISTINCT(SELECT count(id)FROM) commercial_lease LENGTH(CONCAT(地区,城市,"奥克兰"))= LENGTH(位置))作为listing_without_address,(SELECT count(id)FROM commercial_lease其中LENGTH(CONCAT(地区,城市,"奥克兰"))< LENGTH(location))作为listing_with_address,(SELECT count(id)FROM commercial_lease WHERE first_agent_name ='无'和 second_agent_name ='无')作为来自commercial_lease")的private_listing;
答案 0 :(得分:0)
你正在混合报价。查询由双引号括起,对于Auckland
,您试图再次将它们放在双引号中,这会发出错误。
要解决此问题,您可以使用\"Auckland\"
或使用单引号'Auckland'
转义字符串
$result = DB::select("select DISTINCT
(SELECT count(id) FROM commercial_lease where LENGTH(CONCAT(region,city,'Auckland')) = LENGTH(location) ) as listing_without_address ,
(SELECT count(id) FROM commercial_lease where LENGTH(CONCAT(region,city,\"Auckland\")) < LENGTH(location)) as listing_with_address ,
(SELECT count(id) FROM commercial_lease WHERE first_agent_name = 'None' and second_agent_name='None') as private_listing from commercial_lease");