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

什么是对此的正确查询。(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.

相关问答

更多
  • 将dictionary1添加到dictionary2 ,您将删除所有对象。 这是在dictionary2中的相同字典(它不创建副本),因此您也从中删除对象。 你需要删除行[dictionary1 removeAllObjects]; 。 然后,由于此时您已完成了dictionary1 ,您可以删除对它的引用或设置为一个可以使用的漂亮的新闪亮字典: // Remove the reference dictionary1 = nil; // Or, create a new, empty dictionary ...
  • 一个标准的方式看起来像这样 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]; }
  • 你的字典是不可变的 - 它是一个NSDictionary,而不是一个NSMutableDictionary。如果你想转换任何(数组,字典) 不可变的mutable使用mutableCopy进行完全转换(平衡保留计数)。 NSMutableDictionary * item = [self.carouselSource[index] mutableCopy]; if([Utils isNull:[item objectForKey:@"image"]]) { [item setObject:@"default ...
  • 根据您的问题,这应该工作 NSLog(@"%@",dataManager.requestComments[[serviceRequest.RequestId stringValue]]); 因为您将密钥作为NSString并且您希望它基于NSNumber返回。 您需要查看用于存储此字典的代码。 更新 您已经提到该密钥是NSNumber类型。 但是你在valueForKey中传递一个字符串并返回一个有效的对象。 您应该检查如何从API响应中形成此字典。 Based on your question, thi ...
  • 你的问题很奇怪。 总之,调试器显示你的字典正确,但是objectForKey返回nil 。 我在最后一个小时想到了这一点,我很确定我只知道这种情况发生的可能性 - 不正确的hash或isEqual:方法。 特别是,我认为isEqual:方法是不对称的。 换句话说,如果我们有 id k = [GAClause parse:@"(x 1 1)"]; 然后 [k isEqual:k] 不一定是真的。 然后,如果你得到你的字典键并试图找到它们的值(这与[NSDictionary description]相同), ...
  • 从Apple的NSUserDefaults objectForKey的文档: 返回的对象是不可变的 ,即使您最初设置的值是可变的。 该行: dictionary = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 丢弃之前创建的NSMutableDictionary并返回一个NSDictionary 。 将加载更改为: NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:@" ...
  • 您的JSON具有字典数组,因此首先将其转换为数组并循环遍历数组。 在每次迭代中,您将拥有一个字典,然后您就可以访问它们。 []显示数组。 for (NSDictionary *dic in jsonArray){ //Now your dic store key value, and value is again in array NSArray *memberArray = [dic objectForKey:@"member"]; //memberArray contain d ...
  • 我想通了,我不需要做任何序列化来做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.
  • 您需要覆盖MyClass init方法并在其中初始化MyMap usemap = [[MyMap alloc] init] 。 然后覆盖MyMap init方法并在其中初始化mmap self.mmap = [[NSMutableDictionary alloc] init] 。 在MyClass重写的init方法中完成剩余的工作。 这是一个粗略的草图: 。H @interface MyClass : something { MyMap* usemap; } @end @interface MyM ...
  • 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.

相关文章

更多

最新问答

更多
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 高考完可以去做些什么?注意什么?
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 怎么在《我的世界》游戏里面编程
  • .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
  • 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
  • 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
  • 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
  • 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
  • 如何使用变量值创建参数类(How to create a parameter class with variant value)
  • 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
  • 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
  • rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
  • 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
  • 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
  • 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
  • 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
  • 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
  • Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
  • 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
  • 函数调用可以重新排序(Can function calls be reordered)
  • 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
  • 如何解释SBT错误消息(How to interpret SBT error messages)
  • 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)