- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Stack Exchange Data Explorer学习 SQL,但我认为该问题的基础知识适用于其他数据库。
我正在尝试查询 Badges
表,根据 Stexdex(从现在开始我将这样调用它),该表具有以下架构:
这对于像 [Epic]
和 [Legendary]
这样具有独特名称的徽章很有效,但是银牌和金牌标签特定的徽章似乎混合在一起通过具有相同的确切名称。
这是我为 [mysql]
标签编写的示例查询:
SELECT
UserId as [User Link],
Date
FROM
Badges
Where
Name = 'mysql'
Order By
Date ASC
(略有注释的)输出是:as seen on stexdex :
User Link Date
--------------- ------------------- // all for silver except where noted
Bill Karwin 2009-02-20 11:00:25
Quassnoi 2009-06-01 10:00:16
Greg 2009-10-22 10:00:25
Quassnoi 2009-10-31 10:00:24 // for gold
Bill Karwin 2009-11-23 11:00:30 // for gold
cletus 2010-01-01 11:00:23
OMG Ponies 2010-01-03 11:00:48
Pascal MARTIN 2010-02-17 11:00:29
Mark Byers 2010-04-07 10:00:35
Daniel Vassallo 2010-05-14 10:00:38
这与当前列表silver一致和 gold截至 2010 年 5 月底,只有 2 名用户获得了金 [mysql]
标签:Quassnoi 和 Bill Karwin,如上面的结果是他们的名字是唯一出现两次的名字。
我是这样理解的:
Id
第一次出现(按时间顺序)是为了银徽章现在,上面的结果将白银和黄金条目混合在一起。我的问题是:
GROUP BY Id
并以某种方式选择 Date
的最小值/最大值或第一个/第二个?最初我想要以下输出,本质上是:
User Link Date
--------------- -------------------
Bill Karwin 2009-02-20 11:00:25 // result of query for silver
Quassnoi 2009-06-01 10:00:16 // :
Greg 2009-10-22 10:00:25 // :
cletus 2010-01-01 11:00:23 // :
OMG Ponies 2010-01-03 11:00:48 // :
Pascal MARTIN 2010-02-17 11:00:29 // :
Mark Byers 2010-04-07 10:00:35 // :
Daniel Vassallo 2010-05-14 10:00:38 // :
------- maybe some sort of row separator here? can SQL do this? -------
Quassnoi 2009-10-31 10:00:24 // result of query for gold
Bill Karwin 2009-11-23 11:00:30 // :
但到目前为止,对于白银和黄金的单独列的答案也很好,所以也可以随意追求这个角度。不过,我仍然很好奇您将如何执行上述操作。
最佳答案
Is this a typical design, or are there much friendlier schema/normalization/whatever you call it?
当然,您可以添加类型代码以使其更明确。但是当你考虑到一个人不能在获得银徽章之前获得金徽章时,日期戳就很适合区分它们。
In the current design, how would you query the silver and gold badges separately? GROUP BY Id and picking the min/max or first/second by the Date somehow?
是的 - 加入派生表(也称为内联 View ),该表是用户列表和最短日期将返回银徽章。使用 HAVING COUNT(*) >= 1
也可以。您必须结合使用 GROUP BY 和 HAVING COUNT(*) = 2` 才能获得金徽章 - 最大日期不能确保用户 ID 有多个记录...
How can you write a query that lists all the silver badges first then all the gold badges next?
抱歉 - 用户,还是先是银牌再是金牌?前者可以简单地通过使用 ORDER BY t.userid, t.date
来完成;后者我可能会使用分析函数(即:ROW_NUMBER()、RANK())...
Is it perhaps more typical to do two totally separate queries instead?
请参阅上面关于您的要求有多模糊,无论如何对我...
What is this idiom called? A row "partitioning" query to put them into "buckets" or something?
您所问的内容由以下同义词指代:Analytic、Windowing、ranking...
关于sql - 初学者SQL问题: querying gold and silver tag badges in Stack Exchange Data Explorer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2985415/
我们可以使用GCM通知作为APNS徽章图标在iPhone应用程序上显示徽章编号吗 由于我无法使用GCM进行设置。 我推荐this link这说 Parameter Platform
注册推送通知时,我没有启用角标(Badge)警报... - (void)registerForPushNotifications { UIRemoteNotificationType noti
我向用户推送了一个没有角标(Badge)键或角标(Badge) = 0 的通知负载,通知无法从通知中心删除。这是我的有效负载: { "aps" : {"alert" : "bala bala
我想在用户每次打开应用程序时清除应用程序图标角标(Badge)。在我的应用程序中,我使用以下代码清除角标(Badge): [UIApplication sharedApplication].appli
在第二版中我可以使用 badge badge-important 我发现 .badge 元素不再具有上下文(-success、-primary 等)类。 如何在版本 3 中实现同样的效果? 例如。我希
Yii2 Twitter Bootstrap 徽章 颜色不变。 In browser source i cant find badge-success, badge-danger e.t.cclass
我目前正在设计一个教育网站。 为此,我们需要根据用户的事件(例如stackoverflow)为他们分配一些徽章。 我正在为此寻找框架。任何人都有任何想法,如何做到这一点? table 设计等 我可以想
我正在制作一个应用程序,该程序显示自从两个人建立关系以来的天数。我想在应用程序图标徽章上显示天数。我知道一旦用户离开应用程序该怎么做,但是我想每天更新图标徽章,即使该应用程序未在后台打开或在后台运行也
我是 iPhone开发的新手。我只是创建像聊天应用程序之类的应用程序。很简单,我使用JSON解析方法,并通过PHP从服务器调用数据并将其发送回给他们。 所以我有一个UIButton我想在此上设置徽章U
我想在控制SplitView中弹出框的UIBarButtonItem上添加徽章 这段代码什么都不做: - (void)splitViewController: (UISplitViewControll
也许这是一个简单的问题... 我有一个带有3个ViewController的3个选项卡栏项的UITabBarController。 我能够将Badge(通过使用setBadgeValue)添加到选项卡
我正在开发 react-native iOS 中的聊天应用程序。我想在收到通知、应用程序被杀死或用户强制退出时在主应用程序图标上进行标记增量。当应用程序处于后台模式时,它运行良好。但是 didRece
当我收到消息时,我会将用户名和未读消息计数写入 CoreData。并借助此功能: func unreadMessagesCountBadge(cell: onlineUserCell, forCoun
这是我的代码,我将日期放在应用程序角标(Badge)中。我想知道如何每天重新加载这个号码而不进入应用程序重新加载它。提前致谢! NSDate *today = [NSDate date]; NSCal
我有一个带有标签栏 Controller 的应用程序。这些 View 之一是 TableView 。有一种方法可以在标签栏中设置此 View 的角标(Badge)。这有效......但只有当用户触摸此
在我的数据库中,我将传递的消息计数存储在一个表字段中。对于我发送到特定设备的每条消息,我都会增加这个值。 当设备收到带有角标(Badge)设置的 payloa 时,它会在应用程序图标上显示红色圆圈。
我的应用程序包含许多嵌入式练习,这些练习会在应用程序使用期间显示给用户。我计划发布我的应用程序的定期更新,其中包含额外的练习。每次(标准应用程序商店应用程序)更新后,我想在应用程序图标上添加一个角标(
我试图了解当用户的网络连接特别差或没有网络连接时,iOS 上远程通知的最佳实践。 场景是这样的: 用户会收到一些远程通知,并在将来的某个时候打开应用程序。此时,我不想让服务器尽快知道角标(Badge)
我有一个函数,可以在单元格上添加角标(Badge): unreadMessagesCountBadge(cell, forCount: messagesCount) 但我不知道,如何检测我需要添加此角
我的问题的根源是我无法在真实设备上测试推送消息,因为这个问题似乎是 Xcode bug,但这不是现在的主题。我只是添加这个来回答为什么我不能正常测试我的实现。 因此,我使用 OneSignal SDK
我是一名优秀的程序员,十分优秀!