我的查询有问题。
MySQL 查询:
SELECT DISTINCT(`users`.`username`), `users`.`full_name`, `users`.`profile_picture_url`,
`users`.`followed_by_count`, `users`.`follows_count`, `users`.`bio`, `users`.`id`
FROM `users`,`interests`
LEFT JOIN `blocked`
ON `blocked`.`receiver_id` = `users`.`id`
AND `blocked`.`actor_id` = 100
AND `blocked`.`blocked_reason` = 'Blocked'
WHERE `blocked`.`receiver_id` IS NULL
AND `users`.`instagram_active` = 1
AND `users`.`banned` = 0
AND `interests`.`user_id` = `users`.`id`
AND `interests`.`interest` = 'Food'
AND `interests`.`active` = 1
AND `users`.`active` = 1
ORDER BY `users`.`last_login` DESC
LIMIT 0, 25
我得到的错误是这样的:
1054 - Unknown column 'users.id' in 'on clause'
当我选择它时,它是一个未知列怎么办?
我很迷茫...
用户:
CREATE TABLE `users` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`instagram_id` int(11) NOT NULL,
`username` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`bio` text COLLATE utf8_unicode_ci,
`website` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`profile_picture_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`full_name` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`media_count` int(11) unsigned NOT NULL,
`followed_by_count` int(11) unsigned NOT NULL,
`follows_count` int(11) unsigned NOT NULL,
`last_updated` datetime NOT NULL,
`last_updated_instagram` datetime NOT NULL,
`instagram_active` tinyint(1) DEFAULT NULL,
`last_login` datetime NOT NULL,
`inserted_on` datetime NOT NULL,
`banned` tinyint(1) NOT NULL DEFAULT '0',
`banned_reason` text COLLATE utf8_unicode_ci,
`oauth_token` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`user_level` tinyint(4) NOT NULL,
`shown_to_others` tinyint(1) NOT NULL DEFAULT '1',
`credits_offered` tinyint(1) unsigned NOT NULL DEFAULT '2',
`active` tinyint(1) NOT NULL DEFAULT '1',
`email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`registered_ip` varchar(17) COLLATE utf8_unicode_ci DEFAULT NULL,
`credits` int(11) NOT NULL,
`email_notifications` tinyint(1) NOT NULL DEFAULT '1',
`todays_followers` int(11) NOT NULL DEFAULT '0',
`todays_followers_hour` int(11) NOT NULL,
`total_followers` int(11) NOT NULL,
`credits_yesterday` int(11) NOT NULL,
`email_is_verified` tinyint(1) NOT NULL DEFAULT '0',
`email_announcements` tinyint(1) NOT NULL DEFAULT '1',
`email_credits` tinyint(1) NOT NULL DEFAULT '1',
`verification_code` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
`country_id` bigint(20) unsigned DEFAULT NULL,
`browser_info_id` bigint(20) unsigned DEFAULT NULL,
`featured_user` tinyint(1) NOT NULL DEFAULT '0',
`emailed_credits` tinyint(1) NOT NULL DEFAULT '0',
UNIQUE KEY `id` (`id`),
UNIQUE KEY `instagram_id` (`instagram_id`),
KEY `country_id` (`country_id`),
KEY `browser_info_id` (`browser_info_id`),
KEY `username` (`username`,`instagram_active`,`banned`),
CONSTRAINT `users_ibfk_1` FOREIGN KEY (`country_id`) REFERENCES `countries` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `users_ibfk_2` FOREIGN KEY (`browser_info_id`) REFERENCES `browser_info` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1279 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
兴趣:
CREATE TABLE `interests` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`interest` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`inserted_dt` datetime NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
UNIQUE KEY `id` (`id`),
KEY `user_id` (`user_id`),
KEY `interest` (`interest`),
CONSTRAINT `interests_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4161 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
已阻止:
CREATE TABLE `blocked` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`actor_id` bigint(20) unsigned NOT NULL,
`receiver_id` bigint(20) unsigned DEFAULT NULL,
`blocked_reason` enum('Skipped','Blocked') COLLATE utf8_unicode_ci NOT NULL,
`inserted_dt` datetime NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
`browser_info_id` bigint(20) unsigned DEFAULT NULL,
UNIQUE KEY `id` (`id`),
KEY `actor_id` (`actor_id`,`receiver_id`),
KEY `receiver_id` (`receiver_id`),
KEY `browser_info_id` (`browser_info_id`),
CONSTRAINT `blocked_ibfk_1` FOREIGN KEY (`actor_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `blocked_ibfk_2` FOREIGN KEY (`receiver_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `blocked_ibfk_3` FOREIGN KEY (`browser_info_id`) REFERENCES `browser_info` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5700 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
最佳答案
根据 JOIN Syntax 记录:
Join Processing Changes in MySQL 5.0.12
[ deletia ]
Previously, the comma operator (
,) andJOINboth had the same precedence, so the join expressiont1, t2 JOIN t3was interpreted as((t1, t2) JOIN t3). NowJOINhas higher precedence, so the expression is interpreted as(t1, (t2 JOIN t3)). This change affects statements that use anONclause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.Example:
CREATE TABLE t1 (i1 INT, j1 INT); CREATE TABLE t2 (i2 INT, j2 INT); CREATE TABLE t3 (i3 INT, j3 INT); INSERT INTO t1 VALUES(1,1); INSERT INTO t2 VALUES(1,1); INSERT INTO t3 VALUES(1,1); SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);Previously, the
SELECTwas legal due to the implicit grouping oft1,t2as(t1,t2). Now theJOINtakes precedence, so the operands for theONclause aret2andt3. Becauset1.i1is not a column in either of the operands, the result is anUnknown column 't1.i1' in 'on clause'error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for theONclause are(t1,t2)andt3:SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);Alternatively, avoid the use of the comma operator and use
JOINinstead:SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);This change also applies to statements that mix the comma operator with
INNER JOIN,CROSS JOIN,LEFT JOIN, andRIGHT JOIN, all of which now have higher precedence than the comma operator.
关于MySQL 左连接(未知列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443343/
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
require"socket"server="irc.rizon.net"port="6667"nick="RubyIRCBot"channel="#0x40"s=TCPSocket.open(server,port)s.print("USERTesting",0)s.print("NICK#{nick}",0)s.print("JOIN#{channel}",0)这个IRC机器人没有连接到IRC服务器,我做错了什么? 最佳答案 失败并显示此消息::irc.shakeababy.net461*USER:Notenoughparame
考虑一下:现在这些情况:#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2我需要用其他字符串输出URL。我如何保证&符号不会被转义?由于我无法控制的原因,我无法发送&。求助!把我的头发拉到这里:\编辑:为了澄清,我实际上有一个像这样的数组:@images=[{:id=>"fooid",:url=>"http://
我看到其他人也遇到过类似的问题,但没有一个解决方案对我有用。0.3.14gem与其他gem文件一起存在。我已经完全按照此处指示完成了所有操作:https://github.com/brianmario/mysql2.我仍然得到以下信息。我不知道为什么安装程序指示它找不到include目录,因为我已经检查过它存在。thread.h文件存在,但不在ruby目录中。相反,它在这里:C:\RailsInstaller\DevKit\lib\perl5\5.8\msys\CORE\我正在运行Windows7并尝试在Aptana3中构建我的Rails项目。我的Ruby是1.9.3。$gemin
我有一个super简单的脚本,它几乎包含了FayeWebSocketGitHub页面上用于处理关闭连接的内容:ws=Faye::WebSocket::Client.new(url,nil,:headers=>headers)ws.on:opendo|event|p[:open]#sendpingcommand#sendtestcommand#ws.send({command:'test'}.to_json)endws.on:messagedo|event|#hereistheentrypointfordatacomingfromtheserver.pJSON.parse(event.d
我已经开始使用mysql2gem。我试图弄清楚一些基本的事情——其中之一是如何明确地执行事务(对于批处理操作,比如多个INSERT/UPDATE查询)。在旧的ruby-mysql中,这是我的方法:client=Mysql.real_connect(...)inserts=["INSERTINTO...","UPDATE..WHEREid=..",#etc]client.autocommit(false)inserts.eachdo|ins|beginclient.query(ins)rescue#handleerrorsorabortentirelyendendclient.commi
我有一个Rails应用程序,它在名为properties的字段中存储序列化哈希。虽然哈希键是未知的,所以我不知道有什么方法可以通过强参数实现这一点。谷歌搜索时,我发现了这个:https://github.com/rails/rails/issues/9454,但我想不出具体的解决方案。基本上,我的问题是:如何配置强参数以允许使用未知键的散列?感谢大家的帮助! 最佳答案 我最近遇到了同样的问题,我使用来自https://github.com/rails/rails/issues/9454的@fxn方法解决了它对于以properties
我有一个ruby脚本可以打开与Apple推送服务器的连接并发送所有待处理的通知。我看不出任何原因,但当Apple断开我的脚本时,我遇到了管道损坏错误。我已经编写了我的脚本来适应这种情况,但我宁愿只是找出它发生的原因,这样我就可以在第一时间避免它。它不会始终根据特定通知断开连接。它不会以特定的字节传输大小断开连接。一切似乎都是零星的。您可以在单个连接上发送的数据传输或有效负载计数是否有某些限制?看到人们的解决方案始终保持一个连接打开,我认为这不是问题所在。我看到连接在3次通知后断开,我看到它在14次通知后断开。我从未见过它能超过14点。有没有人遇到过这种类型的问题?如何处理?