sql语句中,select的条件group by having能和where做或运算么?
现在有这个的具体例子,数据库结构如下:user_iduser_scoortypetime12011585222我要在表中查找出,user_id的记录条数大于30条的或者是...
现在有这个的具体例子,数据库结构如下:
user_id user_scoor type time
1 20 1 1585222
我要在表中查找出,user_id的记录条数大于30条的或者是time小于3000的。这种group by having和where针对不同的列条件并且做或运算的select语句怎么写? 展开
user_id user_scoor type time
1 20 1 1585222
我要在表中查找出,user_id的记录条数大于30条的或者是time小于3000的。这种group by having和where针对不同的列条件并且做或运算的select语句怎么写? 展开
2个回答
展开全部
where条件:where user_Id > 30 or time < 3000
group by中having条件: group by field having (user_id>30 or time <3000)
group by having 例子(mysql中验证)
select * from sword_1_instrument
group by dateTime having( value > 1000 or dateTime < '2011-07-12 00:00:00')
order by value desc, dateTime
group by中having条件: group by field having (user_id>30 or time <3000)
group by having 例子(mysql中验证)
select * from sword_1_instrument
group by dateTime having( value > 1000 or dateTime < '2011-07-12 00:00:00')
order by value desc, dateTime
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select *
from table1
group by user_id
having count(user_id) > 30
intersect
select *
from table1
where time < 3000
from table1
group by user_id
having count(user_id) > 30
intersect
select *
from table1
where time < 3000
追问
intersect不是求交集么?我要的是并集。是或者,或者count(user_id) > 30
或者time < 3000 ,可以用那个?
追答
union
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询