我在Maria Db phpMyAdmin Ver:4.8.3上为MySQL构建了以下查询:
数据库服务器
Server: 127.0.0.1 via TCP/IP
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.1.36-MariaDB - mariadb.org binary distribution
Protocol version: 10
Web服务器
Apache/2.4.34 (Win32) OpenSSL/1.1.0i PHP/7.2.10
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 7.2.10
SQL
SELECT tblhoadon.MaHoaDon,
tblkhachhang.HoVaTen,
tblphongtro.MaSoPhong,
tblphongtro.GiaThue,
tbldichvu.MaDichVu,
tblchitietdv.TenChiPhi,
tblchitietdv.ThanhTien,
tblhoadon.TongTien
FROM tblhoadon,
tblphongtro,
tbldichvu,
tblchitietdv
WHERE tblhoadon.MaKhachHang = tblkhachhang.MaKhachHang,
tblhoadon.MaSoPhong = tblphongtro.MaSoPhong,
tblhoadon.MaDichVu = tbldichvu.MaDichVu,
tbldichvu.MaDichVu = tblchitietdv.MaDichVu LIKE 10040001
报告错误
1064-您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以使用正确的语法
tblhoadon.MaSoPhong附近= tblphongtro.MaSoPhong,tblhoadon.MaDichVu =第1行的tbldichvu.MaD'
您能帮我解决语法错误吗?
答案 0 :(得分:1)
您不能仅仅具有一系列条件。它们之间需要一些逻辑运算符,例如and
或or
。
此外,最后一个条件有几个问题:
and
运算符。like
并不是完全错误的,但这样做毫无意义,您可以使用=
条件:
SELECT tblhoadon.MaHoaDon,
tblkhachhang.HoVaTen,
tblphongtro.MaSoPhong,
tblphongtro.GiaThue,
tbldichvu.MaDichVu,
tblchitietdv.TenChiPhi,
tblchitietdv.ThanhTien,
tblhoadon.TongTien
FROM tblhoadon,
tblphongtro,
tbldichvu,
tblchitietdv
WHERE tblhoadon.MaKhachHang = tblkhachhang.MaKhachHang AND
tblhoadon.MaSoPhong = tblphongtro.MaSoPhong AND
tblhoadon.MaDichVu = tbldichvu.MaDichVu AND
tbldichvu.MaDichVu = tblchitietdv.MaDichVu AND
tblchitiedv.MaDichVu = '10040001'