sql - 这个 MySQL 查询有什么问题?

标签 sql mysql tsql

抱歉,这是一个菜鸟问题。我是 MySQL 新手:

我写了这样一个查询:

SELECT
    u.userid, u.alias, g.company_name,
 v.endtime - v.begintime AS duration, 
    u.status, u.service_starttime,
 u.service_expiretime, v.begintime, u.email
FROM
    company_users c, company_groups g INNER JOIN
    user_info u INNER JOIN vfon_log v 
    ON (u.userid = v.hostid) ON (g.company_id = u.company_id)

此查询返回语法错误:

Query : SELECT        u.userid, u.alias, g.company_name, v.endtime - v.begintime AS duration, u.status, u.service_starttime, u.service_ex...
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON (g.company_id = u.company_id)
 LIMIT 0, 1000' at line 4
Execution Time : 00:00:00:000
Transfer Time  : 00:00:00:000
Total Time     : 00:00:00:000

我已经花了 30 分钟查看,但我无法弄清楚哪里出了问题。

非常感谢你的帮助

最佳答案

ON (g.company_id = u.company_id)

应该在 INNER JOIN user_info u 之后

这样就变成了

SELECT
    u.userid, u.alias, g.company_name,
 v.endtime - v.begintime AS duration, 
    u.status, u.service_starttime,
 u.service_expiretime, v.begintime, u.email
FROM
    company_users c, company_groups g 
INNER JOIN user_info u ON (g.company_id = u.company_id)
INNER JOIN vfon_log v  ON (u.userid = v.hostid) 

关于sql - 这个 MySQL 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3226838/

相关文章:

MySQL Like 函数仅适用于某些表

mysql - 选择包含每天最大值的整行

php - MYSQL:选择与另一个表的多行相关的条目

mysql - rails : can't get the attributes from the joined table

sql-server - 如何使用sql终止 session

Sql单索引或多索引

sql - 将日期时间转换为 float 时,SQL 的转换函数如何工作?

php - 简短的 php/mysql 查询删除两个表选择的位置

Sql 密码生成器 - 8 个字符,大写和小写,并包含数字

php - SQL查询优化转换