什么是对此的正确查询。(What's the proper query for this. (needs orderby, make some of the values be last and more) MYSQL)
表:用户,学生,组
用户:
行:Username
值:Teacher2
,Teacher3
,Teacher4
,Teacher4
学生们:
行:grpID
,Name
值:(1,John),(1,Joe),(1,Rose),(2,Gina),(2,Mark),(2,Jack),(3,Ted),(4,Fred)团体:
行:grpID
,Handler
值(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)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
最满意答案
你的问题很奇怪。 总之,调试器显示你的字典正确,但是
objectForKey
返回nil
。我在最后一个小时想到了这一点,我很确定我只知道这种情况发生的可能性 - 不正确的
hash
或isEqual:
方法。特别是,我认为
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
returnsnil
.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
orisEqual:
methods.Especially, I think that the
isEqual:
method is not symmetric. In other words, if we haveid 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
intoisEqual
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]; }
-
iOS:无法在NSMutableDictionary中设置空值(iOS: can't set the null value in an NSMutableDictionary)[2023-10-13]
你的字典是不可变的 - 它是一个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]相同), ...
-
为什么NSUserDefaults无法保存NSMutableDictionary?(Why does NSUserDefaults fail to save NSMutableDictionary?)[2023-09-06]
从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.