我收到以下错误:无法重新打开表:'t1'错误。请协助

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我收到以下错误:无法重新打开表:'t1'错误。请协助相关的知识,希望对你有一定的参考价值。

我收到#1137 - Can't reopen table: 't1'错误

我的示例代码如下

CREATE TEMPORARY TABLE  temp_table ( INDEX(productName),INDEX(age))
AS 

 select productName,age from productsmarket Inner Join customer on productsmarket.customer_username = customer.username;


 select    distinct t1.productName, (

select age

from temp_table t2

 where t2.productName = t1.productName

group by age

order by count(*) desc

limit 1
)

as age

from temp_table t1

我想返回两列productNameage

答案

我认为您不需要创建临时表(或永久表)来执行此操作。一个密集的排名功能(在mysql 8中更容易),但在这里模拟。

drop table if exists productsmarket;
CREATE table productsmarket (productname varchar(3),customer_username int);
insert into productsmarket values
('aaa',4),('aaa',2),('aaa',4),
('bbb',1),('bbb',4);

和客户

+------+------+------+
| id   | name | age  |
+------+------+------+
|    1 | abc  |   10 |
|    2 | def  |   10 |
|    3 | ghi  |   10 |
|    4 | jkl  |   11 |
|    5 | jkl  |   11 |
+------+------+------+
5 rows in set (0.04 sec)

select productname,age,obs,
         if(productname <> @p, @rn:=1,if(obs <> @po,@rn:=@rn+1,@rn:=@rn)) denserank,
         @p:=productname pname,
         @po:=obs po
from
( 
select productName,age,count(*) obs
from productsmarket 
Inner Join customer on productsmarket.customer_username = customer.id
group by productName,age
) s
cross join (select @rn:=0,@p:=0,@po:=0) r
having denserank = 1
order by productname,obs desc
;

+-------------+------+-----+-----------+-------+----+
| productname | age  | obs | denserank | pname | po |
+-------------+------+-----+-----------+-------+----+
| aaa         |   11 |   2 | 1         | aaa   |  2 |
| bbb         |   10 |   1 | 1         | bbb   |  1 |
| bbb         |   11 |   1 | 1         | bbb   |  1 |
+-------------+------+-----+-----------+-------+----+

在抽奖的情况下,密集排名很有用。

以上是关于我收到以下错误:无法重新打开表:'t1'错误。请协助的主要内容,如果未能解决你的问题,请参考以下文章

arcmap打开属性表的时候出现:“不能从数据源中加载数据,如果你能改正错误,按刷新按钮重新加载数据

绕过 MySQL“无法重新打开表”错误

Apache服务name报如下错误:无法打开日志

无法重新打开 DSP 设备 /dev/dsp:权限被拒绝

将 Postgres 表导出到 csv

当我在 iPad 上收到“无法验证应用程序”错误时该怎么办?