- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 sql 中遇到了一个小问题,我无法找到构建正确语句的方法。当出现“etud”和“mod”相等时,我只需要在结果中包含具有最大“sess”的行:
etud|sess|mod|eta
1------1---M1--nv
1------2---M1--v
2------1---M1--nv
3------1---M1--v
4------1---M1--v
现在我需要的结果是:
etud|sess|mod|eta
1------2---M1--v
2------1---M1--nv
3------1---M1--v
4------1---M1--v
提前致谢。
最佳答案
这真的只是一个MAX()
aggregate , 按 etud
和 mod
分组:
SELECT
etud,
MAX(sess) AS sess,
mod
FROM yourtable
GROUP BY etud, mod
虽然 MySQL 允许您简单地将列添加到上面的查询中,而无需将其添加到 GROUP BY
中,但是您为该列获得的值是不确定的,如果您有多个可能的值,您无法计划返回哪一个(通常它会是第一个)。
要拉入与 MAX(sess)
匹配的剩余 eta
列,您可以加入子查询。
SELECT
main.etud,
maxsess.maxsess AS sess
main.mod,
main.eta
FROM
yourtable
JOIN (
SELECT
etud,
MAX(sess) AS maxsess,
mod
FROM yourtable
GROUP BY etud, mod
/* JOIN all 3 columns of the subquery which gets the MAX() against the rest of the table */
) maxsess ON main.etud = maxsess.etud AND main.sess = maxsess.maxsess AND main.mod = maxsess.mod
关于mysql - SQL : Select the max of two occurrences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12831170/
我知道,我不是第一个问这个的人。我在堆栈本身中发现了很多问题,比如 Delete only one instance of a recurring event from my Android cale
我有一个字符串: a = '0202201131181' 我想用单个 1 替换 a 中所有多次出现的 1 ,但如果只有一次 '1 ' 找到然后用空字符串 '' 替换它。 我的最终目标是: a = '0
我需要在给定日期之后从 loginhistory 表中查找重复出现的用户登录。我尝试了以下查询,但它给出了零行。 loginhistory 表有两列,即 userkeyid 和 datecreated
我有两个数据集,我想要的可能被松散地称为“非关键变量的外部连接”。 这是数据集 数据集 1 oc oc2 state_id r_state A011 A01 1808 1.00
因此,此方法会传递一个 Occurences 数组列表,其中每个包含一个字符串和一个频率。频率是这里唯一重要的部分。但我需要做的是使用二分搜索将 arraylist 中的最后一个元素插入到排序位置。每
谁能告诉我为什么以下内容不匹配: >>> re.search(r'(\d{2, 10})', '153') 这个匹配: >>> re.search(r'\d{3}', '153') 最佳答案 re模
我尝试定义以下类型 Inductive t : Type -> Type := | I : t nat | F : forall A, (t nat -> t A) -> t A. 我收到以下
这是我的代码片段: import Control.Monad.State as S get x = x + 1 现在,如果我尝试使用 get,我会收到以下错误: Ambiguous occurrenc
当您在 NetBeans 7 中选择一个变量时,使用 PHP(也适用于其他语言),程序会突出显示文件中使用相同变量的所有位置。 我知道如何更改实际突出显示文本的颜色(在 Options->Fonts
这个问题已经有答案了: How to get multiple regex matches in Java? (2 个回答) 已关闭 3 年前。 我有一个电话号码和其他文本列表,如下所示: +1-70
这个问题已经有答案了: How to Count Repetition of Words in Array List? (5 个回答) 已关闭5 年前。 我使用 Collections.frequen
我有一个翻译表,其中有一列重复包含值(语言名称)。如下: id | neutral text | language | translation ---+--------------+---------
我已尝试实现这篇文章中的想法,以按每对的出现顺序对我的输出进行排序 - MySQL: Count occurrences of distinct values 我需要的是能够考虑两个不同的列,而不仅仅
假设我有以下内容: items : (item separator)+ 这适用于: i1, i2, i3, 但不适用于: i1, i2, i3 如何做到不需要结尾分隔符? 最佳答案 这看起来更像是您需
这个问题在这里已经有了答案: Replace all NSNull objects in an NSDictionary (8 个答案) 关闭 8 年前。 我有一个 NSArray其中包含 stri
我有以下文本文件。 foo1 bam foo1 bam foo2 bam foo1 zip foo2 boo foo1 zip foo3 zip 我想制作一个
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
在 OCaml 中,如何在正则表达式中指定模式的出现次数?我浏览了 Str 模块,找不到 {n} 的等效项量词。 例如,如果我想指定一个“年份”模式,即正好 4 位数字,除了执行 "[0-9][0-9
我有一个很大的data.table(这里只显示了五行)。 taxpath
我有一张这样的表: col1 col2 id1 item1 id1 item2 id1 item3 id2 item1 id2 item4 i
我是一名优秀的程序员,十分优秀!