通过案例陈述从组中获取外来关键项目的数量

时间:2018-08-02 03:09:46

标签: mysql sql foreign-keys

尝试了解mysql联接,并有一个基本示例可以使用。我想弄清楚如何合并两个表并按年龄组对销售量进行分组。

People table:
id            age
1             11
2             23
3             17
4             14
5             24
6             19
7             21

Other table:
id          
1           
2           
3            
4            
5           

Middle table
id          o_id         p_id
1           3            1
2           1            5
3           5            3
4           4            7
5           2            6
6           5            2
7           3            4
8           1            7
9           3            5
10          2            3

age     Total Other for each age group
10-20         5
20-30         5

2 个答案:

答案 0 :(得分:2)

select count(*),
    case
        when age between 11 and 20 then '11-20'
        when age between 21 and 30 then '21-30'
    end as aggage
from Customer inner join Sale
    on Customer.id = Sale.c_id
group by aggage

您应该只能够加入Sale表以计算销售额。 Here it is working

答案 1 :(得分:0)

    for (x,y), value in numpy.ndenumerate(plt)
      plt[x,y].set_xlabel(...)
      plt[x,y].set_xticks([...])

以上工作。 enter image description here