不使用分析函式找每個月銷量最高的車型

2022-07-28 02:51:11 字數 1230 閱讀 7807

不使用分析函式計算每個月每種車型銷售前3的行

create view  test_sale  as

select '2019-01' as order_date,'a' as brand_id ,10 as cnt from dual union all

select '2019-01' as order_date,'b' as brand_id ,20 as cnt from dual union all

select '2019-01' as order_date,'c' as brand_id ,30 as cnt from dual union all

select '2019-01' as order_date,'d' as brand_id ,15 as cnt from dual union all

select '2019-01' as order_date,'e' as brand_id ,22 as cnt from dual union all

select '2019-02' as order_date,'a' as brand_id ,10 as cnt from dual union all

select '2019-02' as order_date,'b' as brand_id ,30 as cnt from dual union all

select '2019-02' as order_date,'c' as brand_id ,30 as cnt from dual union all

select '2019-02' as order_date,'d' as brand_id ,15 as cnt from dual union all

select '2019-02' as order_date,'e' as brand_id ,22 as cnt from dual ;

自關聯,使用月份關聯,關聯後,匹配當前月銷售量比本車型銷售量大的資料。

彙總後,行數最少的,就是銷售量最多的。

select a.order_date, a.brand_id, a.cnt, count(*) as rn

from test_sale a

join test_sale b

on a.order_date = b.order_date

and a.cnt <= b.cnt

group by a.order_date, a.brand_id, a.cnt;

不使用例項名呼叫函式

class method def init self,a self.a a def cls method1 self print 需要傳入乙個引數,使用例項名呼叫此函式 def cls method2 print 不需要傳入引數,使用類名呼叫此函式 staticmethod def class me...

何時使用或何時不使用malloc函式

在初學資料結構時,我們往往不太清楚在定義乙個結構體指標時要不要使用malloc函式。例如以下的 linklist init linklist retrun h linklist s s data x 以上這兩句 是不行的,因為s沒有指向確切的位址,所以不能通過s來向它要指向的位址賦值 但是linkl...

何時使用或何時不使用malloc函式

在初學資料結構時,我們往往不太清楚在定義乙個結構體指標時要不要使用malloc函式。例如以下的 linklist init linklist retrun h linklist s s data x 以上這兩句 是不行的,因為s沒有指向確切的位址,所以不能通過s來向它要指向的位址賦值 但是linkl...