我在oracle中編寫了一個腳本。但它並沒有給我我想要的結果。 我需要這個,想象我有兩張桌子。 Order_table和書桌。 我的訂單表是這樣的在其他表中計算一個表的字段
ORDER_TABLE表
ID TYPE_ID VALUE_ID
1 11 null
2 11 null
3 11 null
4 12 null
5 11 null
書表
ID ORDER_TYPE DELETED
1 1 F
2 null F
3 5 F
4 5 F
5 4 F
6 4 F
7 3 T
我的劇本是這樣的
Select *
From (
Select Newtable.Counter As Value_id,
o.Id As Id,
o.Type_id As Type_id
From (
Select (Count B.Order_Type) As Counter,
B.Order_Type As Id
From Book B
Where B.Deleted = 'F'
Group By B.Order_Type
Order By Count(B.Order_Type) Desc
) newtable,
order_table o
where o.id = newtable.id
and o.type_id = 11
)
order by id asc;
結果是這樣的。
Value_ID TYPE_ID ID
2 11 5
2 11 4
1 11 1
沒有顯示第二和第三個id有0個計數,我能顯示0個計數嗎?
結果應該是這樣的。
Value_ID TYPE_ID ID
2 11 5
2 11 4
1 11 1
0 11 2
0 11 3
order_table和book_table之間的關係是什麼? – Prathyush