mysql 分组数据查询问题
迷茫
迷茫 2017-04-17 13:34:39
0
1
345

表 A 字段如下
union_id --主键
name
agent_id --1对多

表B字段如下
id
name
union_id --外键
endtime --时间戳格式

表A的union_id,name,表B中当前时间(精确到年月日)未超过endtime的总数和已超过endtiome的总数,以上字段为一条数据
如何根据表A的agent_id查询出满足条件的数据集合

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (1)
大家讲道理

Someone gave me how to write oracle. I’m not familiar with oracle, please translate it

SELECT a.union_id, COUNT(*), COUNT(isMoreEndtime) --这是大于的,小于的拿count减下就可以了 FROM a, (SELECT b.union_id, decode(b.endtime, 1, 0) isMoreEndtime --自己去时间比较下,大于的标1,小的就0 FROM b WHERE b.union_id = 'xx') bb WHERE a.union_id = bb.union_id(+) AND a.union_id = 'xx' GROUP BY a.union_id
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!