选择count(*)多行并显示结果

发布于 2024-12-08 22:04:40 字数 487 浏览 0 评论 0原文

我必须执行一个包含 SELECT COUNT 的 UPDATE 表,但这花费的时间太长。 这是我原来的查询,

 UPDATE list SET count = 
 (SELECT COUNT(*) FROM set_1 WHERE set_1.start BETWEEN list.start AND list.end); 

我只有 100 行需要更新,所以我想只做一个选择计数并将其显示在屏幕上。然后我会将结果复制/粘贴到我的 Excel 电子表格上。

我本来打算这样做,但它只返回一个数字(而不是 100 行数字),

 SELECT COUNT(*) FROM set_1,list WHERE set_1.start BETWEEN list.start AND list.end;

但这不起作用,它返回所有 SELECT COUNT 中的一大数字。

任何人都可以帮我解决这个问题吗?

I have to do an UPDATE table that includes a SELECT COUNT but that takes way too long.
That was my original query

 UPDATE list SET count = 
 (SELECT COUNT(*) FROM set_1 WHERE set_1.start BETWEEN list.start AND list.end); 

I just have 100 rows to update so I was thinking of just do a select count and display it on screen. And then I'll copy/paste the result on my excel spreadsheet.

I was intended to do this, but it returns only one number (and not 100 rows of number)

 SELECT COUNT(*) FROM set_1,list WHERE set_1.start BETWEEN list.start AND list.end;

But that doesn't work it returns one big number of all the SELECT COUNT together ..

Anyone can help me out with this ?

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

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

发布评论

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

评论(1

画▽骨i 2024-12-15 22:04:40

您正在 set1 和 list 之间进行笛卡尔积

select        
   (SELECT COUNT(*) FROM set_1 
         WHERE set_1.start BETWEEN list.start AND list.end) as [count]
from list

You are doing a cartesian product between set1 and list

select        
   (SELECT COUNT(*) FROM set_1 
         WHERE set_1.start BETWEEN list.start AND list.end) as [count]
from list
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文