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?
 
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
 
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.