Mysql 查找整个组的列值为“P”的行
我有台式摄像机,我需要找到只使用过摄像机模式“p”而没有其他模式的摄像机Mysql 查找整个组的列值为“P”的行,mysql,sql,Mysql,Sql,我有台式摄像机,我需要找到只使用过摄像机模式“p”而没有其他模式的摄像机 select * from (select Cam_serial_no, collect_set(camera_mode) as val from camera group by Cam_serial_no ) a where size(val)=1 and val[0] = 'P'; 表结构 Cam_serial_no Camera_mode abc123
select *
from (select Cam_serial_no, collect_set(camera_mode) as val
from camera
group by Cam_serial_no
) a
where size(val)=1 and val[0] = 'P';
表结构
Cam_serial_no Camera_mode
abc123 P
abc123 B
abc123 V
pqr111 P
xyz101 P
xyz101 V
xyz101 B
select *
from (select Cam_serial_no, collect_set(camera_mode) as val
from camera
group by Cam_serial_no
) a
where size(val)=1 and val[0] = 'P';
我可以使用下面的查询获得所需的输出,但我想知道是否有简单的方法
select *
from (select Cam_serial_no, collect_set(camera_mode) as val
from camera
group by Cam_serial_no
) a
where size(val)=1 and val[0] = 'P';
期望输出为
select *
from (select Cam_serial_no, collect_set(camera_mode) as val
from camera
group by Cam_serial_no
) a
where size(val)=1 and val[0] = 'P';
pqr111 P
按Cam_序列号分组,只取除p以外没有其他模式的模式
select *
from (select Cam_serial_no, collect_set(camera_mode) as val
from camera
group by Cam_serial_no
) a
where size(val)=1 and val[0] = 'P';
按Cam_序列号分组,只取除p以外没有其他模式的模式
select *
from (select Cam_serial_no, collect_set(camera_mode) as val
from camera
group by Cam_serial_no
) a
where size(val)=1 and val[0] = 'P';
您正在寻找HAVING子句。见juergen d对此的回答。检查数值的方法有很多种;e、 g.having mincamera_mode='P'和maxcamera_mode='P'。您正在寻找having子句。见juergen d对此的回答。检查数值的方法有很多种;e、 g.让mincamera_mode='P'和maxcamera_mode='P'。嗨,Juergen,当我在Hive中运行您的查询时,我得到了以下错误;失败:UDFArgumentTypeException仅接受数字或字符串类型参数,但传递布尔值。因为MySQL!=蜂箱语法不同。这应该适用于几乎所有的数据库引擎:当摄像头模式为“P”时,使用sumcase,然后使用1 else 0 end=0Hi Juergen,当我在配置单元中运行您的查询时,我得到以下错误;失败:UDFArgumentTypeException仅接受数字或字符串类型参数,但传递布尔值。因为MySQL!=蜂箱语法不同。这应该适用于几乎所有的DB引擎:当摄像头模式为“P”时,使用sumcase,然后使用1 else 0 end=0