Getting the count of DISTINCT of several columns
How can i get the count of DISTINCT of several columns?
SQL> select count(distinct ename) from emp;
COUNT(DISTINCTENAME)
14
SQL> select count(distinct ename, job) from emp;
select count(distinct ename, job) from emp
ERROR at line 1:
ORA-00909: invalid number of arguments
Hello,
You should separate them out like this
select count(distinct ename), count(distinct job) from emp;Regards
Similar Messages
-
How to get the count of distinct customer in matrix?
Hi,
I want to get the count of distinct customer in matrix at the time of validation event.
Thanks Regards,Hi,
Please close the thread.by marking the correct answer
regards,
Prasad -
To get the count of records and able to access the column value in a single
Hi
Is there any way to get the number of records in the query and access the column values
e.g
select count(*)
from
(SELECT department, COUNT(*) as "Number of employees"
FROM employees
WHERE salary > 25000
GROUP BY department ) a
This wil only get the Count, if i want to access each row from the inline view how can i do that.Your question is not clear.
Are you looking for total record count as well as count by department ?
Something like this?
SQL>
SQL> with temp as
2 (
3 select 1 dept ,10000 sal from dual union
4 select 1 dept ,25100 sal from dual union
5 select 1 dept ,30000 sal from dual union
6 select 1 dept ,40000 sal from dual union
7 select 2 dept ,10000 sal from dual union
8 select 2 dept ,25100 sal from dual union
9 select 2 dept ,30000 sal from dual union
10 select 2 dept ,40000 sal from dual )
11 select count(*) over( partition by 1 ) total_count,dept,
12 count(*) over(partition by dept) dept_cnt from temp
13 where sal>25000;
TOTAL_COUNT DEPT DEPT_CNT
6 1 3
6 1 3
6 1 3
6 2 3
6 2 3
6 2 3
6 rows selected
SQL> -
Need to get the count based on the column availability
You get a set of table names from a query, say
select table_name from all_tab_columns where column_name like 'DC_I’;
TABLE_NAME
A
B
C
Now, for the above set of tables (A,B and C), you need to get the count(*) for a single dc_i value (say XXX DC)
In simple words, its like framing the following 4 separate queries into one single one:
select table_name from all_tab_columns where column_name like 'DC_I’; (Based on this o/p, following 3 queries..)
select count(*) from A where dc_i=XXX;
select count(*) from B where dc_i=XXX;
select count(*) from C where dc_i=XXX;
ThanksAre you looking for this?
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:01.04
satyaki>
satyaki>
satyaki>
satyaki>SELECT table_name,
2 DBMS_XMLGEN.getxmltype ('SELECT Count(*) c FROM ' || table_name||' where '||column_name|
|' = 10').EXTRACT ('//text()').getnumberval() tot_rows
3 FROM all_tab_cols
4 WHERE table_name in ('EMP', 'DEPT')
5 and column_name = 'DEPTNO';
TABLE_NAME TOT_ROWS
EMP 4
DEPT 1
Elapsed: 00:00:01.00
satyaki>
satyaki>
satyaki>
satyaki>select count(*) from emp where deptno = 10;
COUNT(*)
4
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>select count(*) from dept where deptno = 10;
COUNT(*)
1
Elapsed: 00:00:00.00
satyaki>Regards.
Satyaki De. -
How to get the count of each minutes
Oracle 10 DB
Hi All
I using this query to get the count of records fetched by the concurrent program per min,
select count (distinct b.attribute2)
from oe_order_headers_all a,oe_order_lines_all b
where a.header_id=b.header_id
and b.flow_status_code ='AWAIT_QUINTIQ_BOOK'
and to_Char(b.last_update_date,'DD-MON-YYYY HH24:MI:SS') between '19-JAN-2011 02:00:01' AND
'19-JAN-2011 02:00:02'
This is used to get the count of records fetched at one mins
How to find the count of last 10 mins ie 1 mins count 2.00 to 2.10
Thanks & Regards
Srikkanth.MTry this:
SELECT TRUNC(b.last_update_date, 'mi') time_mins, COUNT(DISTINCT b.attribute2)
FROM oe_order_headers_all a,
oe_order_lines_all b
WHERE a.header_id = b.header_id
AND b.flow_status_code = 'AWAIT_QUINTIQ_BOOK'
AND b.last_update_date >= to_date('19/01/2011 02:00:00', 'dd/mm/yyyy hh24:mi:ss')
AND b.last_update_date < to_date('19/01/2011 02:10:00', 'dd/mm/yyyy hh24:mi:ss')
GROUP BY TRUNC(b.last_update_date, 'mi');I'm not sure why you're bothering with the join to the oe_order_headers_all table, since you're not referencing that in the where clause or the selected columns list. I think you could probably do away with it.
I've changed your code to take the last_update_date and truncate it to the minute level, and added that as a column, so you can see which count goes with which minute. Obviously, this has to be in the group by.
I've also changed your date comparisons so that you're actually comparing dates to dates, rather than strings to strings - why would you deliberately take information away from the optimizer? Oracle does not treat strings the same as dates, and forcing it to use strings rather than dates could lead you to have a vastly differing execution path, which will most likely be less performant.
Not to mention, coding like that leads you to assume that you can compare dates in strings without any problems, and that is just not the case. '19-FEB-2011' is counted as being earlier than '19-JAN-2008', as strings sort alphabetically. -
I'm trying to get the count for each row to total count for each month
Something like this
Hardware | Jan
Monitors | 5
Processors | 137
Printers | 57
etc........
How can I write a query for this. I can get the Hardware column but don't know how to get the next column.If you can provide more data like sample input DML statements it would have been wonderful..
Assuming is , you need a pivot. Here is an article on basic Pivot..
http://sqlsaga.com/sql-server/how-to-use-pivot-to-transform-rows-into-columns-in-sql-server/
something like this may be..
DECLARE @Input TABLE
Hardware VARCHAR(20),
[Date] VARCHAR(20)
INSERT INTO @Input VALUES('Monitor', '01/01/2014'), ('CPU', '01/01/2014'), ('Monitor', '01/03/2014')
, ('ABC', '01/01/2014'),('Monitor', '02/01/2014')
;WITH CTE AS
SELECT Hardware, LEFT(DATENAME(M, [Date]),3) AS [MonthName] FROM @Input
SELECT *
FROM
SELECT Hardware, [MonthName], COUNT(Hardware) AS Count FROM CTE GROUP BY Hardware, [MonthName]) a
PIVOT (MAX([Count]) FOR [MonthName] IN ([Jan], [Feb])) pvt
Please mark as answer, if this has helped you solve the issue.
Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles. -
How to get the count of PO'S raised by a user
Hi,
I have a new requirement whr i am asked to get the count of number of PO'S raised by a particular user in report. Suppose the user raised 10 purchase orders .
The requirement is when a user name is given it has to give count of 10.
Where shud i include this,in rows or columns. Please suggest.
Thanks&Regards,
PraveenHi Praveen,
take a look in www.service.sap.com/bi, under old release, for release 2.x you will find an How to that detail how to count occurencies of a Char. Maybe you will find here the solution.
Ciao.
Riccardo. -
How to get the Count of a logic?
Hi,
Very new to CRM. I am trying to get the count of "activity start time" that are greater than current time stamp. Count(activity start time) work. I don't know how to add the time stamp condition to this. I can't add this condition as filter.
Appreciate any responses.
ThanksRaghu,
Thanks for the help. It works to get the count.
The problem is, i have some other filters set and can't combine this filter. Here is my scenario:
get all activities on a contact that have greater than x $ amount as assets. I need to find the number of future appointments for that contact and start time of first pending future appointment. All has to be in one report.
My columns are for example : contact name, activity start time, end time, subject, next pending appointment start time, total future appointments, some other related fields from contact
So when I add the filter that you had given, it will not give me all activities. I am able to achieve all this in seperate reports and unnable to get it in single one.
Thanks,
GiGi -
SQ01 - SAP List Viewer - Ability to get the count of the output records
Hello All,
I have a problem with the SAP List Viewer output for an SAP Query.
I have created a SAP query (SQ01) for a table. Its a basic query that queries on just one table (VTBFHA)
When I run the query, for the output in the SAP List Viewer (ALV) format, Could anyone kindly help me figure out how to get the count of the number of records displayed in the output?
For Eg: when we run the T code SE16, It gives us the number of records displayed in the output.
Similarly, does anyone know if there is a way I could display the count of the number of records displayed in the output of the SQ01 query?
I have tried checking the "Counter" in the basic list tab, but it does not give me the count.
Any help will be greatly appreciated
Thanks
SubhaniYes there is a solution. Follow these steps
Select your query
Hit the button InfoSet Query
Go to Edit->Settings->
Check the box "Count in the Output list" in the Output tab
Hit Save
In pop up box select the user group
hit enter
Hit the back arrow (F3)
now Execute the query
You should be able to see the count in the output.
The count will appear on the right most column of the output. If it does not go to the "Change layout" option and make sure it is part of the "Displayed columns list".
Regards -
How can i get the count vaule from GPIB?
I want to get the count waule from GPIB ,but I find that the vaule I get from GPIB now is the trace vaule ,
so I ask How can i get it.The count of what? What kind of instrument are you using?
-
Get the count of rows in a table control
Hi Experts,
How do I get the count of the rows in a table control during run time.
I am developing a BDC in which I have to check all entries in a table control.
My requirement is to get the total number of rows in a table control dynamically.
Thanks
KumarHi,
Use a variable when u r passing the records from the internal table to the screen fields
and display the same.
I think this idea may help u.
And pls explain me ur requirement clearly.
Refer to the following link this may help u.
http://sapabapnotes.blogspot.com/2008/03/working-with-ecatt-extended-computer.html
Reward if helpful.
Jagadish -
I have an older iPod (2005). After years of inactivity I tried to install the cd on my PC. I get the following error message, after several attempts to install: iTunes cannot run because some of its required files are missing. Please re install iTunes.
Did you follow the exact instructions in this Apple support document to remove and re-install iTunes and ALL other Apple software on your XP machine?
Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
B-rock -
Select Count(*) from Sample_table - how to get the count using JDBC?
Hi All,
It would be glad if anyone could help me with this. The problem is that I have to get the 'count' of records selected from a arbitrary table say, 'sample_table'. Is that possible to form the SQL in JDBC as
Select Count(*) from Sample_table
and get the value of the count? If yes, how?
Thanks in advance
Prabzstmt = con.createStatement();
ResultSet recordcnt_rs = stmt.executeQuery("Select Count (*) as record_ctr From Sample_table");
recordcnt_rs.next();
record_ctr = recordcnt_rs.getInt("record_ctr");
hope this helps. -
I always get the count as 0 for the variable. I am not sure what I am doing wrong. Please let me know if any of you know the fix.
ThanksHere is the query I used now. Still same result
SELECT (select count(*) from usr_all_mbrs where PREMIER_YN = 'Y') AS count1
SELECT
(select
count(*)
from usr_all_mbrs
where PREMIER_YN
=
'Y')
AS count1 -
How do I get the Layout Guides (A,B,C column headers and 1,2,3 Row Headers) to print on my spreadsheet? They are invaluable for discussing the data with my clients over the phone.
They appear while I am editing, but don't print with the spreadsheet. I know how to do it in Excel, but I am transitioning to Numbers. I can't imagine I have to type them into their own columns and rows. It must be a difference in vernacular that I can't find the solution in the User Guide. Can anyone help?Hi ktjobauer,
Numbers is not Excel and Excel is not Numbers. Numbers is WYSIWYG (at least in File > Print and the actual printout).
I can't imagine I have to type them into their own columns and rows.
No, you don't. You can use the charm of Numbers to create cell references for your Excel clients.
In this Numbers Table, I have added some extra Columns that you can hide later.
Column B =COLUMN(A2)
Column C =HLOOKUP(B2,'Table 1-1' :: $1:$2,2,FALSE) [explanation later]
Column D =ROW(B2)
Column E =C2&D2
Add those formulas to the first Body Row (below the Header Row) and Fill Down.
Column C refers to another Table which you need only create once, to convert a Column number to a letter:
and so on from 1-26, A-Z.
You can move the second Table to another Sheet to hide it. Formulas will automatically adjust to keep the links between Sheets.
Now in the first Table, select and Hide Columns B,C,D. Formulas will continue to work with hidden cells:
Regards,
Ian.
Maybe you are looking for
-
I need to figure out how to get IMessage.
-
I'm having two problems with attachments in Mail that I can't find described/solved in any discussion. (1) When people send me Word files (.doc extension) they are displayed inline (encoded) rather than as icons, e.g.: --Apple-Mail-11--306075396 Cont
-
VC 7.1 table - number of columns
Hi all, Does anyone knows if I can manipulate with the current row number of a table. That means for example, can I have a separate column that prints the number of the current row? Thanks in advance! Best regards, Vera
-
I understand that in OWB 9.0.4, available in Feb 2003, process flow diagrams can be drawn within the OWB design UI elegantly. Does this also mean that we can schedule jobs to run from within OWB 9.0.4 instead of using another scheduling tool (e.g. OE
-
Csom javascript get Document Libraries with particular Content Type
I need to filter result to particular content types fo document library. I cannot seem to retrieve the content type of library. How is this <g class="gr_ gr_29 gr-alert gr_gramm Punctuation multiReplace" data-gr-id="29" id="29">possible.</g> When I t