什么是对此的正确查询。(What's the proper query for this. (needs orderby, make some of the values be last and more) MYSQL)

表:用户,学生,组

用户:
行: Username
值: Teacher2Teacher3Teacher4Teacher4

学生们:
行: grpIDName
值:(1,John),(1,Joe),(1,Rose),(2,Gina),(2,Mark),(2,Jack),(3,Ted),(4,Fred)

团体:
行: grpIDHandler
值(1,教师1),(2,教师2),(3,教师3),(4,教师4)

在此处输入图像描述

我想在有人登录时查询(让我们说老师1)

Select `Name` from Students where (I don't know the proper condition here) Order by `Name`

但这是我想要的结果:

Fred
Gina
Jack
Mark
Ted
Joe
John
Rose

我希望由Teacher1处理的这3名学生(作为登录的示例用户)是要在查询结果上显示的最后一条记录。


Table: Users, Students, Groups

Users:
Rows: Username
Values: Teacher1, Teacher2, Teacher3, Teacher4

Students:
Rows: grpID, Name
Values: (1, John), (1, Joe), (1, Rose), (2, Gina), (2, Mark), (2, Jack), (3, Ted), (4, Fred)

Groups:
Rows: grpID, Handler
Values (1, Teacher1), (2, Teacher2), (3, Teacher3), (4, Teacher4)

enter image description here

I want to query that when someone is logged in (let's say Teacher1)

Select `Name` from Students where (I don't know the proper condition here) Order by `Name`

but here's the result that I want:

Fred
Gina
Jack
Mark
Ted
Joe
John
Rose

I want those 3 students handled by Teacher1 (as example user who logged in) to be the last record to be shown on the result of the query.


原文:https://stackoverflow.com/questions/34840774
2024-04-21 11:04

满意答案

你的问题很奇怪。 总之,调试器显示你的字典正确,但是objectForKey返回nil

我在最后一个小时想到了这一点,我很确定我只知道这种情况发生的可能性 - 不正确的hashisEqual:方法。

特别是,我认为isEqual:方法是不对称的。 换句话说,如果我们有

id k = [GAClause parse:@"(x 1 1)"];

然后

[k isEqual:k]

不一定是真的。

然后,如果你得到你的字典键并试图找到它们的值(这与[NSDictionary description]相同),则找不到这些值。

我相信你应该把你的断点/ NSLog放入isEqual并观察比较值时发生了什么。

另请注意,字典键已被复制,因此在复制过程中可能会出现相等问题。


Your problem is very strange. In summary, debugger shows your dictionary as correct but objectForKey returns nil.

I was thinking about this for the last hour and I am pretty sure I know only about one possibility how this can happen - incorrect hash or isEqual: methods.

Especially, I think that the isEqual: method is not symmetric. In other words, if we have

id k = [GAClause parse:@"(x 1 1)"];

then

[k isEqual:k]

doesn't have to be true.

Then, if you get your dictionary keys and try to find their values (which is the same [NSDictionary description] does), the values are not found.

I believe you should put your breakpoint/NSLog into isEqual and watch what is happening when values are compared.

Also note that the dictionary keys are copied, so the equality problem can arise during copying.

相关问答

更多

从NSMutableDictionary中获取NSMutableDictionary的值(Get the values from NSMutableDictionary inside NSMutableDictionary)

将dictionary1添加到dictionary2 ,您将删除所有对象。 这是在dictionary2中的相同字典(它不创建副本),因此您也从中删除对象。 你需要删除行[dictionary1 removeAllObjects]; 。 然后,由于此时您已完成了dictionary1 ,您可以删除对它的引用或设置为一个可以使用的漂亮的新闪亮字典: // Remove the reference dictionary1 = nil; // Or, create a new, empty dicti...

循环通过NSMutableDictionary(looping through an NSMutableDictionary)

一个标准的方式看起来像这样 for(id key in myDict) { id value = [myDict objectForKey:key]; [value doStuff]; } A standard way would look like this for(id key in myDict) { id value = [myDict objectForKey:key]; [value doStuff]; }

iOS:无法在NSMutableDictionary中设置空值(iOS: can't set the null value in an NSMutableDictionary)

你的字典是不可变的 - 它是一个NSDictionary,而不是一个NSMutableDictionary。如果你想转换任何(数组,字典) 不可变的mutable使用mutableCopy进行完全转换(平衡保留计数)。 NSMutableDictionary * item = [self.carouselSource[index] mutableCopy]; if([Utils isNull:[item objectForKey:@"image"]]) { [item setObject:@"de...

NSMutableDictionary返回null(NSMutableDictionary returning null)

根据您的问题,这应该工作 NSLog(@"%@",dataManager.requestComments[[serviceRequest.RequestId stringValue]]); 因为您将密钥作为NSString并且您希望它基于NSNumber返回。 您需要查看用于存储此字典的代码。 更新 您已经提到该密钥是NSNumber类型。 但是你在valueForKey中传递一个字符串并返回一个有效的对象。 您应该检查如何从API响应中形成此字典。 Based on your question...

NSMutableDictionary中的对象突然变为空(Object in NSMutableDictionary suddenly becomes null)

你的问题很奇怪。 总之,调试器显示你的字典正确,但是objectForKey返回nil 。 我在最后一个小时想到了这一点,我很确定我只知道这种情况发生的可能性 - 不正确的hash或isEqual:方法。 特别是,我认为isEqual:方法是不对称的。 换句话说,如果我们有 id k = [GAClause parse:@"(x 1 1)"]; 然后 [k isEqual:k] 不一定是真的。 然后,如果你得到你的字典键并试图找到它们的值(这与[NSDictionary description...

为什么NSUserDefaults无法保存NSMutableDictionary?(Why does NSUserDefaults fail to save NSMutableDictionary?)

从Apple的NSUserDefaults objectForKey的文档: 返回的对象是不可变的 ,即使您最初设置的值是可变的。 该行: dictionary = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 丢弃之前创建的NSMutableDictionary并返回一个NSDictionary 。 将加载更改为: NSData *data = [[NSUserDefaults standardUserDefaults]objectForK...

将JSON解析为NSMutableDictionary问题(Parsing JSON into NSMutableDictionary issue)

您的JSON具有字典数组,因此首先将其转换为数组并循环遍历数组。 在每次迭代中,您将拥有一个字典,然后您就可以访问它们。 []显示数组。 for (NSDictionary *dic in jsonArray){ //Now your dic store key value, and value is again in array NSArray *memberArray = [dic objectForKey:@"member"]; //memberArray cont...

NSMutableDictionary不接受某些字符(NSMutableDictionary not accepting certain characters)

我想通了,我不需要做任何序列化来做JSON的内置转换器。 我刚刚传递了正常的字符串。 I figured it out, I didn't need to do any serialization to do JSON's built in converter. I just passed the normal string.

无法使NSMutableDictionary工作(xcode)(Can't get NSMutableDictionary to work (xcode))

您需要覆盖MyClass init方法并在其中初始化MyMap usemap = [[MyMap alloc] init] 。 然后覆盖MyMap init方法并在其中初始化mmap self.mmap = [[NSMutableDictionary alloc] init] 。 在MyClass重写的init方法中完成剩余的工作。 这是一个粗略的草图: 。H @interface MyClass : something { MyMap* usemap; } @end @interfac...

JSONRepresentation为NSMutableDictionary(JSONRepresentation for NSMutableDictionary)

JSONRepresentation方法来自json-framework 。 在项目中包含该框架并导入正确的标题,您应该很高兴。 The JSONRepresentation method comes from json-framework. Include that framework in your project and import the correct headers, and you should be good to go.

相关文章

更多

Solr 使用自定义 Query Parser

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom ...

Solr 使用自定义 Query Parser

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom ...

my php & mysql FAQ

php中文字符串长度及定长截取问题使用str_len("中国") 结果为6,php ...

Mysql错误:Ignoring query to other database解决方法

用source c:\xxx.sql,出现Ignoring query to other databa ...

[How to] Make custom search with Nutch(v 1.0)?(转)

http://puretech.paawak.com/2009/04/29/how-to-make-c ...

Solr与Mysql集成指南

Solr与Mysql集成指南 chuanliang于 2011-9-24,20:28 Comm ...

Solr与Mysql集成指南

在《企业级搜索引擎Solr使用入门指南》及《企业级搜索引擎Solr交流》中对Solr的使用做了简单介绍 ...

常用HQL(Hibernate Query Language)查询

查询一个对象(实体类必须有一个不带参数的构造方法),使用select查询,基于投影的查询,通过在列表中 ...

solr学习笔记二-------solr query查询的参数

初步接触solr是对其query的各个参数都不是很了解,现在做一个总结,以便日后查看使用 各个参数及意 ...

最新问答

更多

python的访问器方法有哪些

使用方法: class A(object): def foo(self,x): #类实例方法 print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): #类方法 print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): #静态方法 print "executing static_foo(%s)"%x调用方法: a =

使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)

我认为你必须将两个TableGetway传递给UserTable构造。 你必须改变Module.php看看: public function getServiceConfig() { return array( 'factories' => array( 'User\Model\UserTable' => function($sm) { $userTableGateway = $sm->get('UserTable

透明度错误IE11(Transparency bug IE11)

这是一个渲染错误,由使用透明度触发,使用bootstrap用于在聚焦控件周围放置蓝色光环的box-shadow属性。 可以通过添加以下类覆盖来解决它。 .form-control:hover { -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); box-shadow: 0px 0px 4px 0px rgba(0,0,255,1)

linux的基本操作命令。。。

ls 显示目录 mkdir 建立目录 cd 进入目录

响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)

将z-index设置为.main-nav这将解决您的重叠问题 .main-nav { position:relative; z-index:9; } set z-index to .main-nav This will fix your overlaping issue .main-nav { position:relative; z-index:9; }

在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)

这是因为模式规范"a"打开一个文件以便追加,文件指针在末尾。 如果您尝试从此处读取,则由于文件指针位于EOF,因此没有数据。 您应该打开"r+"进行阅读和写作。 如果在写入之前读取整个文件,则在写入更多数据时,文件指针将正确定位以追加。 如果这还不够,请探索ftell()和fseek()函数。 That is because the mode spec "a" opens a file for appending, with the file pointer at the end. If you

NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)

支持空中接口的数据速率是一回事。 在消除协议开销,等待eeprom写入以及所有需要时间的其他内容之后,您看到的数据速率是完全不同的故事。 长话短说,从标签读取或进行对等传输时的实际数据速率峰值约为2.5千字节/秒。 取决于具体的标签或对等技术,它可能比这慢很多。 The supported data-rates of the air-interface are one thing. The data-rate that you see after removing protocol overhe

元素上的盒子阴影行为(box-shadow behaviour on elements)

它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂

Laravel检查是否存在记录(Laravel Checking If a Record Exists)

这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found

设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)

$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640