having count oracle query

Hello Experts:

I have following query:

SELECT
    p7.CO_STRING2 as "Folder1",
    p6.CO_STRING2 as "Folder2",
    p5.CO_STRING2 as "Folder3",
    p4.CO_STRING2 as "Folder4",
    p3.CO_STRING2 as "Folder5",
    p2.CO_STRING2 as "Folder6",
    p.CO_STRING2 as "Folder7",
    d.E_NAME,
d.*
  FROM schema.ELEMENT d
       INNER JOIN schema.FLDR_KW f ON d.E_NAME = f.kw_e_name
       INNER JOIN schema.CUSTOM p ON f.KW_NAME =  '{' || p.CO_OBJECT_TYPE || '}' || p.CO_KEY
       LEFT JOIN schema.CUSTOM p2 ON p2.CO_KEY = p.CO_STRING1
       LEFT JOIN schema.CUSTOM p3 ON p3.CO_KEY = p2.CO_STRING1
       LEFT JOIN schema.CUSTOM p4 ON p4.CO_KEY = p3.CO_STRING1
       LEFT JOIN schema.CUSTOM p5 ON p5.CO_KEY = p4.CO_STRING1
       LEFT JOIN schema.CUSTOM p6 ON p6.CO_KEY = p5.CO_STRING1
       LEFT JOIN schema.CUSTOM p7 ON p7.CO_KEY = p6.CO_STRING1
      ;

Open in new window


I want to get count of d.e_name if its greater than 1 and get d.* values...
LVL 5
CalmSoulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chris1582Commented:
You can use something like below:
COUNT( employee_id) OVER ( PARTITION BY employee_id)
or
use a sub query in the select clause

(SELECT
    p7.CO_STRING2 as "Folder1",
    p6.CO_STRING2 as "Folder2",
    p5.CO_STRING2 as "Folder3",
    p4.CO_STRING2 as "Folder4",
    p3.CO_STRING2 as "Folder5",
    p2.CO_STRING2 as "Folder6",
    p.CO_STRING2 as "Folder7",
    d.E_NAME,
    (SELECT
     Count (d.E_NAME)
  FROM schema.ELEMENT d
       INNER JOIN schema.FLDR_KW f ON d.E_NAME = f.kw_e_name
       INNER JOIN schema.CUSTOM p ON f.KW_NAME =  '{' || p.CO_OBJECT_TYPE || '}' || p.CO_KEY
       LEFT JOIN schema.CUSTOM p2 ON p2.CO_KEY = p.CO_STRING1
       LEFT JOIN schema.CUSTOM p3 ON p3.CO_KEY = p2.CO_STRING1
       LEFT JOIN schema.CUSTOM p4 ON p4.CO_KEY = p3.CO_STRING1
       LEFT JOIN schema.CUSTOM p5 ON p5.CO_KEY = p4.CO_STRING1
       LEFT JOIN schema.CUSTOM p6 ON p6.CO_KEY = p5.CO_STRING1
       LEFT JOIN schema.CUSTOM p7 ON p7.CO_KEY = p6.CO_STRING1
/* You can even ad a where clause here if you like for example: where   d.e_name > 1
and you reference it to the outer a table too just make sure you use a different names. */
      ) as E_name_Count
d.*
  FROM schema.ELEMENT d
       INNER JOIN schema.FLDR_KW f ON d.E_NAME = f.kw_e_name
       INNER JOIN schema.CUSTOM p ON f.KW_NAME =  '{' || p.CO_OBJECT_TYPE || '}' || p.CO_KEY
       LEFT JOIN schema.CUSTOM p2 ON p2.CO_KEY = p.CO_STRING1
       LEFT JOIN schema.CUSTOM p3 ON p3.CO_KEY = p2.CO_STRING1
       LEFT JOIN schema.CUSTOM p4 ON p4.CO_KEY = p3.CO_STRING1
       LEFT JOIN schema.CUSTOM p5 ON p5.CO_KEY = p4.CO_STRING1
       LEFT JOIN schema.CUSTOM p6 ON p6.CO_KEY = p5.CO_STRING1
       LEFT JOIN schema.CUSTOM p7 ON p7.CO_KEY = p6.CO_STRING1
      )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CalmSoulAuthor Commented:
thanks Chris but I am getting error

Lookup Error
ORA-00923: FROM keyword not found where expected
0
chris1582Commented:
Yes that query was not tested because i don't have a connect to do so. But below is a simpler query that you can run w3school and it is the same idea.

SELECT
CustomerID,
CustomerName,
(select Count(OrderID) from Orders ORD where ORD.CustomerID = CUS.CustomerID) as Count_Of_Orders
FROM Customers CUS;
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

chris1582Commented:
sorry looks like it was missing a comma

here you go. you may still need to complete part of the subquery.

(SELECT
    p7.CO_STRING2 as "Folder1",
    p6.CO_STRING2 as "Folder2",
    p5.CO_STRING2 as "Folder3",
    p4.CO_STRING2 as "Folder4",
    p3.CO_STRING2 as "Folder5",
    p2.CO_STRING2 as "Folder6",
    p.CO_STRING2 as "Folder7",
    d.E_NAME,
    (SELECT
     Count (d.E_NAME)
  FROM schema.ELEMENT d
       INNER JOIN schema.FLDR_KW f ON d.E_NAME = f.kw_e_name
       INNER JOIN schema.CUSTOM p ON f.KW_NAME =  '{' || p.CO_OBJECT_TYPE || '}' || p.CO_KEY
       LEFT JOIN schema.CUSTOM p2 ON p2.CO_KEY = p.CO_STRING1
       LEFT JOIN schema.CUSTOM p3 ON p3.CO_KEY = p2.CO_STRING1
       LEFT JOIN schema.CUSTOM p4 ON p4.CO_KEY = p3.CO_STRING1
       LEFT JOIN schema.CUSTOM p5 ON p5.CO_KEY = p4.CO_STRING1
       LEFT JOIN schema.CUSTOM p6 ON p6.CO_KEY = p5.CO_STRING1
       LEFT JOIN schema.CUSTOM p7 ON p7.CO_KEY = p6.CO_STRING1
/* You can even ad a where clause here if you like for example: where   d.e_name > 1
and you reference it to the outer a table too just make sure you use a different names. */
      ) as E_name_Count,
d.*
  FROM schema.ELEMENT d
       INNER JOIN schema.FLDR_KW f ON d.E_NAME = f.kw_e_name
       INNER JOIN schema.CUSTOM p ON f.KW_NAME =  '{' || p.CO_OBJECT_TYPE || '}' || p.CO_KEY
       LEFT JOIN schema.CUSTOM p2 ON p2.CO_KEY = p.CO_STRING1
       LEFT JOIN schema.CUSTOM p3 ON p3.CO_KEY = p2.CO_STRING1
       LEFT JOIN schema.CUSTOM p4 ON p4.CO_KEY = p3.CO_STRING1
       LEFT JOIN schema.CUSTOM p5 ON p5.CO_KEY = p4.CO_STRING1
       LEFT JOIN schema.CUSTOM p6 ON p6.CO_KEY = p5.CO_STRING1
       LEFT JOIN schema.CUSTOM p7 ON p7.CO_KEY = p6.CO_STRING1
      )
0
chris1582Commented:
0
slightwv (䄆 Netminder) Commented:
I do not understand exactly what you are looking for.

Please post sample data and expected results.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.