如何获取 MySQL 中嵌套查询和 WHERE IN 使用查询返回的行数?

发布于 2024-11-25 16:06:40 字数 305 浏览 3 评论 0原文

SELECT kullaniciNick,
       kullaniciAdi,
       kullaniciSoyadi
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)
ORDER BY kullaniciSoyadi

在查询中,我需要行数来检查它是否超过 6 或更少。 当我使用 COUNT(*) 时,我收到一条错误消息。也就是说它必须与 GROUP BY 一起使用。 谢谢。

SELECT kullaniciNick,
       kullaniciAdi,
       kullaniciSoyadi
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)
ORDER BY kullaniciSoyadi

at the query i need the count of rows to check if it is over 6 or less.
When i used the COUNT(*) i got an error message. That said it must used with GROUP BY.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱已欠费 2024-12-02 16:06:40

试试这个:

SELECT kullaniciNick,
       kullaniciAdi,
       kullaniciSoyadi,
       count(*) -- Added this line
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)
GROUP BY 1,2,3 -- Added this line
ORDER BY kullaniciSoyadi

Try this:

SELECT kullaniciNick,
       kullaniciAdi,
       kullaniciSoyadi,
       count(*) -- Added this line
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)
GROUP BY 1,2,3 -- Added this line
ORDER BY kullaniciSoyadi
听闻余生 2024-12-02 16:06:40

您无法获得结果,并且它的大小在一次查询中。
使用 2 个查询。第一个将为您提供结果的大小,第二个将是结果。第一个查询应该是这样的:

SELECT count(*)
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)

第二个查询就像您上面写的查询一样。

You can't have a result, and it's size in one query.
Use 2 queries. First one will give you the size of result and second one will be the result. The First query, should be like this:

SELECT count(*)
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)

the second one , is just like the query you wrote above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文