Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL查询包含不使用WHERE子句的子句_Php_Mysql - Fatal编程技术网

Php MySQL查询包含不使用WHERE子句的子句

Php MySQL查询包含不使用WHERE子句的子句,php,mysql,Php,Mysql,我对having子句和where子句有问题,我得到以下错误: #1054 - Unknown column 'accommodation' in 'where clause' 代码如下: SELECT b.bar_id, b.bar_name, b.bar_image, b.bar_lat, b.bar_lng, b.bar_address, b.bar_phone, b.bar_email, b.bar_open_hours, `category`, ( 637

我对having子句和where子句有问题,我得到以下错误:

#1054 - Unknown column 'accommodation' in 'where clause'
代码如下:

SELECT 
    b.bar_id, b.bar_name, b.bar_image, b.bar_lat, b.bar_lng, 
    b.bar_address, b.bar_phone, b.bar_email, b.bar_open_hours, `category`, 
    ( 6371 * acos( cos( radians(-37.81829) ) * cos( radians( b.bar_lat ) ) * cos( radians( b.bar_lng ) - radians(144.9620) ) + sin( radians(-37.81829) ) * sin( radians( b.bar_lat ) ) ) ) AS distance 
FROM 
    bars b 
WHERE 
    `category` LIKE accommodation 
GROUP BY 
    category 
HAVING 
    distance < 500 
ORDER BY 
    distance
选择
b、 酒吧id、酒吧名称、酒吧图像、酒吧lat、酒吧lng、,
b、 酒吧地址,酒吧电话,酒吧电子邮件,酒吧营业时间,`category`,
(6371*acos(cos(弧度(-37.81829))*cos(弧度(b.bar_-lat))*cos(弧度(b.bar-lng)-弧度(144.9620))+sin(弧度(-37.81829))*sin(弧度(b.bar_-lat)))作为距离
从…起
酒吧b
哪里
`类住宿
分组
类别
有
距离<500
订购人
距离

我不明白为什么我会犯这个错误。有人有什么建议吗?

你有一个名为“住宿”的专栏吗?或者你应该做一个字符串比较,在这种情况下它应该是
“调节”
(用单引号括起来)

你也可以去

`category` = 'accommodation'

由于字符串中没有任何通配符(
%
)。

如果调整是字符串值,则需要将其用单引号括起来。更好的是,没有必要将LIKE用于精确的字符串,您可以使用equals

即:

选择b.bar\u id、b.bar\u名称、b.bar\u图像、b.bar\u lat、b.bar\u lng、b.bar\u地址、b.bar\u电话、b.bar\u电子邮件、b.bar\u开放时间、`category`、(6371*acos(弧度(-37.81829))*cos(弧度(b.bar\u lat))*cos(弧度(弧度(b.bar\u lng)-弧度(144.9620))+sin(弧度(-37.81829))*sin(弧度)(弧度*)\u)作为与酒吧b的距离,其中“类别”=“住宿”按类别分组,距离小于500

您是否缺少有关住宿的单引号,或者它是有效的列名?解决问题的第一步是读取错误消息。住宿是值,类别是列名是“住宿”是db字段还是字符串?如果是字符串,则应该用单引号括起来。再次尝试读取错误消息。我以为我知道SQL,但比较两个不等字符串是否相等有什么意义?如何在having子句中比较上述字符串?
SELECT b.bar_id, b.bar_name, b.bar_image, b.bar_lat, b.bar_lng, b.bar_address, b.bar_phone, b.bar_email, b.bar_open_hours, `category`, ( 6371 * acos( cos( radians(-37.81829) ) * cos( radians( b.bar_lat ) ) * cos( radians( b.bar_lng ) - radians(144.9620) ) + sin( radians(-37.81829) ) * sin( radians( b.bar_lat ) ) ) ) AS distance FROM bars b WHERE `category` = 'accommodation' GROUP BY category HAVING distance < 500 ORDER BY distance