Mysql 使用不同的表创建视图
这里我得到的错误是: 子查询返回多行mysql 当我输入limit 1时,它返回整个表中的一个值。但是我想要所有的行 是否有任何其他选项可以获取所有这些数据Mysql 使用不同的表创建视图,mysql,views,Mysql,Views,这里我得到的错误是: 子查询返回多行mysql 当我输入limit 1时,它返回整个表中的一个值。但是我想要所有的行 是否有任何其他选项可以获取所有这些数据 提前感谢您可以获得每行列表中的所有值。也许这就是你想要的: create view xyz_view as select t1.sam_time, t2.hos_id, (select t1.STAT_VALUE from table_1 t1 where t1.ID = 6 ) as col_1, (s
提前感谢您可以获得每行列表中的所有值。也许这就是你想要的:
create view xyz_view as
select
t1.sam_time,
t2.hos_id,
(select t1.STAT_VALUE from table_1 t1 where t1.ID = 6 ) as col_1,
(select t1.STAT_VALUE from table_1 t1 where t1.ID = 24 ) as col_2,
(select t1.STAT_VALUE from table_1 t1 where t1.ID = 125 ) as col_3,
(select t1.STAT_VALUE from table_1 t1 where t1.ID = 143 ) as col_4
from
table_1 t1, table_2 t2
where
t1.entity = t2.hos_id;
您还应该学会使用适当的
join
语法,它使用join
关键字和on
关键字来表示表之间的条件。我不相信您。如果您的子查询返回多行,那么视图将得到一个大的笛卡尔乘积。你能编辑你的问题并提供样本数据和期望的结果吗?
select
t1.sam_time,
t2.hos_id,
(select group_concat(t1.STAT_VALUE) from table_1 t1 where t1.ID = 6 ) as col_1,
(select group_concat(t1.STAT_VALUE) from table_1 t1 where t1.ID = 24 ) as col_2,
(select group_concat(t1.STAT_VALUE) from table_1 t1 where t1.ID = 125 ) as col_3,
(select group_concat(t1.STAT_VALUE) from table_1 t1 where t1.ID = 143 ) as col_4
from table_1 t1 join
table_2 t2
on t1.entity = t2.hos_id;