Oracle sql - join and group by clause to pull out a top customers with most orders -


edit2: got :

tables : http://imgur.com/a/ecb5t

i trying pull out top of 25% of customers belong company , have orders.

i tried below query:

select customer_id, ( select count(order_id) order  commercial_customer.customer_id = order.customer_id ) orders limit 25/100 * (count(*) order) ; 

but i'm getting

ora-00923: keyword not found expected 00923. 00000 - "from keyword not found expected" *cause:
*action: error @ line: 5 column: 13

after following suggestions comments got query: http://imgur.com/a/9jpyn

it displays right orders 3 both because count(*) counts orders customer_id=2.

in order make work use

select customer_id,customer_name,company_code,orders xyz_customer,xyz_commercial, ( select count(*) orders xyz_order **where customer_id=xyz_comcustomer.customerid** ) rownum<=(select count(*)from xyz_comcustomer)/3 

but getting this:

ora-00904: "xyz_comcustomer"."customerid": invalid identifier 00904. 00000 -  "%s: invalid identifier" *cause:     *action: error @ line: 4 column: 19 

expected result:
customer_id, customer_name,company_code,orders
4 marin 87654321 3
1 alexa 12345678 1

try (with analytical functions)

select *   (    select customer_id, rank() on (order count_orders) rank_orders       (      select customer_id, count(*) count_orders      order      group cusomer_id    )  )  rank_orders <= round((select count(*) order) / 4) 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -