【问题标题】:How do I show the name who has the most dates? like max(count(max(date)))如何显示日期最多的姓名?像 max(count(max(date)))
【发布时间】:2018-11-07 20:26:36
【问题描述】:

我是这样想的:

SELECT l.vorname
     , l.nachname 
  FROM leser l 
  JOIN ausleihe a 
    ON l.LeserNr = a.LeserNr 
 WHERE MAX(COUNT(a.gemahnt)) = 
    (SELECT = COUNT(gemahnt) AS Anzahl 
       FROM ausleihe 
     WHERE Anzahl = (SELECT MAX(Anzahl)));

【问题讨论】:

  • 嗨。这还不清楚。使用足够的单词和句子来表达你的意思。将您的问题放在帖子正文中。该代码与“日期”有什么关系?另外:这(显然)是一个常见问题。请用谷歌搜索一个问题的许多明确措辞。 How to Ask 当您要求重新编码时,请提供 minimal reproducible example

标签: mysql sql join max inner-join


【解决方案1】:
SELECT 
l.Vorname, l.Nachname, COUNT(a.gemahnt) AS Anzahl
    FROM
leser l
    JOIN
ausleihe a ON l.LeserNr = a.LeserNr
   WHERE
a.gemahnt IS NOT NULL
GROUP BY a.LeserNr
HAVING Anzahl = (SELECT 
    COUNT(gemahnt)
FROM
    ausleihe
WHERE
    gemahnt IS NOT NULL
GROUP BY LeserNr
ORDER BY COUNT(gemahnt) DESC LIMIT 1);

:D

【讨论】:

    猜你喜欢
    • 2021-12-28
    • 2021-08-19
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多