How to return rows where count = 0
Hi, I have the below query that returns the quarters along with the number of issues:
select MQTR as Quarter, count(MQTR)
from tbl1, tbl2
where Fdate=Cdate
and cycle_missed = 'Yes'
group by MQTR
order by 1
output:
2006-Q2 1
2006-Q3 1
2007-Q2 2
I know that 2007-Q1 has 0 issues but I can't get the query to return the row with count 0. So my question is how I can get this output:
2006-Q2 1
2006-Q3 1
2007-Q1 0
2007-Q2 2
SQL> create table tbl1
2 as
3 select date '2006-04-10' cdate, '2006-Q3' mqtr from dual union all
4 select date '2006-08-11', '2006-Q4' from dual union all
5 select date '2006-10-12', '2007-Q1' from dual union all
6 select date '2007-02-13', '2007-Q2' from dual
7 /
Tabel is aangemaakt.
SQL> create table tbl2
2 as
3 select date '2006-04-10' run_date, 'Yes' interventions from dual union all
4 select date '2006-04-15', 'Yes' from dual union all
5 select date '2006-08-19', 'No' from dual union all
6 select date '2006-10-20', 'Yes' from dual union all
7 select date '2006-12-20', 'No' from dual union all
8 select date '2007-02-20', 'No' from dual
9 /
Tabel is aangemaakt.
SQL> select tbl1.mqtr
2 , count(tbl2.run_date) "Count"
3 from tbl1
4 , tbl2
5 where tbl1.mqtr = to_char(add_months(tbl2.run_date (+),3),'yyyy-"Q"q')
6 and tbl2.interventions (+) = 'Yes'
7 group by mqtr
8 order by mqtr
9 /
MQTR Count
2006-Q3 2
2006-Q4 0
2007-Q1 1
2007-Q2 0
4 rijen zijn geselecteerd.Regards,
Rob.
Similar Messages
-
Hi All,
Question: How do I filter rows out of a query where multiple columns are equal to a single question mark character?
Background: I'm using SQL 2008 R2. Furthermore, the part of my brain that helps me create less-than-simple queries hasn't been working for the last 4 days, apparently, and now I need help.
We have about 4,000 rows in a table. This data set was generated from an exported report, and many of the rows in the detail table were not actual data rows but were simply "header" rows. For those table rows, most of the columns have
a single question mark as the value.
Some of the detail rows have one or more question mark values, too, so it's important that these rows don't get filtered out.
When I include criteria like "WHERE col1 <> '?' AND col2 <> '?' AND col3 <> '?' AND col4 <> '?'", all rows with a question mark value for even a single one of those columns get filtered out. How do I filter out rows
where all columns 1-4 contain a question mark value?
Thanks for your help,
EricI just tried to create to create a scenario for you. Please see ig you're looking for something like this.
Create table test_Question_mark
RecordID INT identity(1,1),
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10),
Col4 varchar(10),
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','??','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','??','??','??')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ??','??','??')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ?','??','??')
--drop table test_Questio_mark
select * from test_Question_mark
select * from test_Question_mark
WHERE
(CHARINDEX('?', Col1,1) > 0 AND CHARINDEX('?', Col1, CHARINDEX('?', Col1,1)+1) = 0) AND
(CHARINDEX('?', Col2) > 0 AND CHARINDEX('?', Col2, CHARINDEX('?', Col2,1)+1) = 0) AND
(CHARINDEX('?', Col3,1) > 0 AND CHARINDEX('?', Col3, CHARINDEX('?', Col3,1)+1) = 0) AND
(CHARINDEX('?', Col4,1) > 0 AND CHARINDEX('?', Col4, CHARINDEX('?', Col4,1)+1) = 0)
--drop table test_Questio_mark
I hope above solution will help.
Thanks!
Ashish. -
Return rows where date between sysdate +- 2 years
Hi,
Please let me know how to select rows from table where date = sysdate +- 2 years
if sysdate is 27/07/2012 then select rows where date between 27/07/2010 to 27/07/2014you need all date ? or only specific date ?
Specific date Purvesh already provided solution
All
SELECT * FROM ( SELECT SYSDATE+LEVEL AFTER,SYSDATE-LEVEL befor FROM dual connect BY LEVEL<=365*2 )Or specific
SELECT Max(AFTER),Min(befor) FROM
( SELECT SYSDATE+LEVEL AFTER,SYSDATE-LEVEL befor FROM dual connect BY LEVEL<=365*2 ) -
SDO_RELATE to return rows where point is in polygon
Is it possible to return rows from a table where an input point geometry falls within the polygon sdo_geometry column stored in the row? I don't just want to return the geometry, but all columns in the row where the geometry "intersects".
I'm trying this, but run into an error:
SELECT * FROM COUNTY_PARCEL R where SDO_RELATE(R.SHAPE, MDSYS.SDO_GEOMETRY(2001,2868,MDSYS.SDO_POINT_TYPE(656849.49,883088.84,NULL),NULL,NULL), 'mask=anyinteract') = 'TRUE'
ORA-29902: error in executing ODCIIndexStart() routine
ORA-13282: failure on initialization of coordinate transformation
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 286
Any help is much appreciated.
Edited by: user12167574 on Feb 25, 2010 3:10 PMGuddie
YOUR SQL as such should do what you have described, however, the error message "ORA-13282: failure on initialization of coordinate transformation" is indicating an issue with coord transformation.
from the user manual:
"If geometry1 and geometry2 are based on different coordinate systems, geometry2 is temporarily transformed to the coordinate system of geometry1 for the operation to be performed, as described in Section 6.10.1."
could it be that the COUNTY_PARCEL table geometries have a different SRID then 2868 (from your input point geometry)?
might it even be so, that the COUNTY_PARCEL have no srid set?
Can you check that and let us know?
tx
Luc -
How to get rows where a varchar column contain pure numeric value
hi,
i have to make a query from a table that return only the rows where the occurrences of a string column contain a pure numeric value
for example my table MYTABLE have the column COL1 varchar2(100)
with values
row 1 : '100'
row 2 : '101 dalmatiens'
row 3 : '102'
row 4 : 'anything'
i want to get only the rows 1 and 3 which are pure integer so i can sort and compare them like number.
thanksSQL> with rt as
2 (select '100' str from dual union all
3 select '101 dalmatiens' from dual union all
4 select '102' from dual union all
5 select '103 #$&''() 456' from dual union all
6 select 'anything' from dual)
7 /* End of sample data (rt) */
8 select str
9 ,trim(translate(str,'1234567890'||str,'1234567890')) num
10 from rt
11 where trim(translate(str,'1234567890'||str,'1234567890')) is not null;
STR NUM
100 100
101 dalmatiens 101
102 102
103 #$&'() 456 103456
-- Oooooops, I misread and now have corrected it
SQL> with rt as
2 (select '100' str from dual union all
3 select '101 dalmatiens' from dual union all
4 select '102' from dual union all
5 select '103 #$&''() 456' from dual union all
6 select 'anything' from dual)
7 /* End of sample data (rt) */
8 select str
9 ,trim(translate(str,'1234567890'||str,'1234567890')) num
10 from rt
11 where trim(translate(str,'1234567890'||str,'1234567890')) = str;
STR NUM
100 100
102 102Message was edited by:
ushitaki -
How to return rows from tmp table created inside function??
Hi,
I'm trying to return rows from a cursor or table (created within
the function). How do I specify the return type?Hi,
Here is the code that examples to create a function that can
return data from table.This is achieved using REFCURSOR concept.
Hope this helps you.I'm giving all stuff in single PL/SQL
block.You can break it and create a package and declare
refcursor type and function in that as well.
DECLARE
-- Declare generic cursor type
TYPE gencur_type IS REF CURSOR ;
-- Declare generic cursor varaible
gencur gencur_type;
-- Declare record type
TYPE rec_type IS RECORD(descr emp.ename%type) ;
-- Declare record type variable
rec rec_type;
--This how you declare a local function that returns gencrtype
data set
--This function is called in main block
FUNCTION call_refcur return gencur_type
AS
rr gencur_type;
BEGIN
OPEN rr FOR SELECT descr FROM emp;
RETURN rr;
END;-- end of local function
-- Main block begins here
BEGIN
-- Call the local function so that gencur will have
-- the data set returned by select statement
gencur:= call_refcur;
-- Open a loop to test the stuff
LOOP
FETCH gencur INTO rec;
EXIT WHEN gencur%NOTFOUND;
null;
dbms_output.put_line(rec.ename);
END LOOP;
END;
Regards,
Sridhar -
How to return the record count of a query to a number variable
How would I get the record count from a query without using a cursor to step through the query and count the records individually?
query: select * from table1 where column1 = column2
How would I get the record count of the query above?
thanks,
michelleI figured it out
select count(*) into theCount
from ( select * from table1 where column1=column2 );
thanks,
michelle -
How to insert row where DB date field has default value.
APEX 4.1, Oracle 11.2
I'm trying to insert a row using "javascript:addRow();" where the report query is an SQL Query (Updateable Report).
1) Several of the fields are display-only with defaulted values.
2) No problem with the VARCHAR2 fields.
3) And if RUN_DT is a text field, the insert works.
4) But I get errors when trying to make RUN_DT (DD-MON-YYYY) display-only and default it to P63_RUN_DT. I display P63_RUN_DT so I see it is correct.
Now, this is not a new question. See:
Error inserting sysdate with time in tabular form region https://forums.oracle.com/thread/2551916 (Not answered)
Date value in tabular form https://forums.oracle.com/thread/2478358 (Not answered)
Help! Unable to set default date value for Tabular form DB date field! https://forums.oracle.com/thread/2473208 (Not answered)
Default Value Date Picker Field https://forums.oracle.com/thread/2468973 (Not answered)
Tabular Form Default Value PL/SQL https://forums.oracle.com/thread/2464192 (Not answered)
Display 1st region invoice date into tabular form invoice date column. https://forums.oracle.com/thread/2458561 (Not answered)
Default System date and time in Tabular form https://forums.oracle.com/thread/2449615 (Not answered)
Setting default value of Tabular form item is not working https://forums.oracle.com/thread/2396024 (Not answer)
apex tabular form https://forums.oracle.com/thread/2337098 (Not answered)
Various folks recommended using Default PL/SQL and SYSDATE when SYSDATE was the desired default value. That worked for some and not for others. I could not get it to work for me. The errors I receive are "•Column must have a value. (Row 1) " and "ORA-01410: invalid ROWID". I believe the ROWID error is an example of spurious error cascade caused by the RUN_DT problem. I believe it will disappear once the RUN_DT problem is solved.
I will try to replicate on apex.oracle.com
Thoughts?
HowardUpdate: At least in my case, it seems the RUN_DT date column cannot be Standard Report Column. I made it "Display as Text (saves state)". Standard Report Column works for the defaulted VARCHAR2 columns. Go figure!
(more) And I could not get it to work with "Item" (P63_RUN_DT) as the Default. However, it seems to work -- so far -- using Default PL/SQL of TO_DATE(:P63_RUN_DT,'DD-MON-YYYY'). -
Auto Counting Number of Rows Where Data is Entered
I am trying to automatically count the number of rows where data is entered. For example, I have a table with six open rows to enter information. If only three of those rows (A2-A4) had names entered in them, and the next three rows were left blank, can I get each name to equal the value "1" so that I can get a total tally of how many names have been entered? So the final tally in this example would be "3." I appreciate your help!
file:///Users/josephdlugo/Desktop/Screen%20Shot%202014-04-30%20at%2011.58.28%20A M.pngthere is a function, COUNTA(), that will count the number of items that are not empty:
C1=COUNTA(B)
this is shorthand for select cell C1, then type, or copy and paste the formula:
=COUNTA(B)
The COUNTA function returns the number of its arguments that are not empty.
COUNTA(value, value…)
value: Any value or a collectioncontaining any values.
value…: Optionally include one or more additional values or collections. -
How to return a single datetime from multiple rows of MAX(value) in DAX
Hi
I have a Results table with ResultTime, Balance, Equity which is updated with a new row every 5 minutes. I've used SUMX to find opening and closing balances and it has worked so far.
Res_OpeningBalance:=SUMX(TOPN(1,Results,Results[ResultTime],1),[Balance])
Res_ClosingBalance:=SUMX(TOPN(1,Results,Results[ResultTime],0),[Balance])
But when I tried it with dates, the whole thing fell apart.
Res_MaxBalance_Date:=SUMX(TOPN(1,Results,Results[Balance],0),[ResultTime])
Since the highest Balance is likely to be represented through many rows due to it lasting more than 5 minutes, ResultTime (which is unique to each row) is summed up and returns messed up dates well into the future. How to return only one date (first or last
datetime) from the rows where Balance is at max?
I tried a TOPN of TOPN, but Excel was not amused.
=SUMX(TOPN(1,Results,Results[Balance],0),TOPN(1,Results,Results[ResultTime],0))
TIA!
Re
DennisI still don't understand RANKX, but I figured it out anyway. I get the correct data by using:
Res_MaxBalance:=MAX(Results[Balance])
Res_MaxBalanceDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Balance]=MAX(Results[Balance])))
Res_MinBalance:=MIN(Results[Balance])
Res_MinBalanceDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Balance]=MIN(Results[Balance])))
Res_MaxEquity:=MAX(Results[Equity])
Res_MaxEquityDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Equity]=MAX(Results[Equity])))
Res_MinEquity:=MIN(Results[Equity])
Res_MinEquityDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Equity]=MIN(Results[Equity])))
Re
D -
How to find if cursor returned rows
If i have a procedure like
create procedure test as
cursor cur_test is
select col
from table;
begin
delete from tab1 a;
for var_cur_test in cur_test
loop
insert into temp
values(var_cur_test.col);
end loop;
commit;
end;
How do I check if the cursor has returned any rows?
I dont want to delete from tab1 if cursor 'cur_test' does not return any rows and I want to exit out of the proc.
If the cursor returns rows > 0 then I want to delete and do the insert.
Thanks for the help.The scenario is like this.
There is a schema A which has to run a process and populate its tables and at the end of the process(java program) run the procedure which is in schema B to pull data from schema A and populate the tables in schema B. If there is a case where Schema A's process fails( then Schema A's tables end up with no data), the process is still running the procedure in schema B and deleting the data in tables with no data being inserted.
So, I have to check in the procedure if the tables in Schema A have any data before the process can run the proc.
I tried the solution you provided but it returns no data
CREATE OR REPLACE PROCEDURE MMA_TEST
VAR_CONTRACT_ID VARCHAR2
AS
CURSOR CUR_TEST IS
SELECT CMS_CONTRACT_ID,CMS_PLAN_ID
FROM MMA_PLANS
WHERE CMS_CONTRACT_ID = VAR_CONTRACT_ID;
BEGIN
for var_cur_test in cur_test
loop
if (cur_test%rowcount = 1) then
delete from temp ;
end if ;
insert into temp
values(var_cur_test.cms_contract_id,var_cur_test.cms_plan_id);
end loop;
end; -
How to return a profile in Game Center. where you want to enter the old nikneim?
How to return a profile in Game Center. where you want to enter the old nikneim?
It's not actually round. It is slight flattened vertically.
Anyway...
I have an Action that places guides at 50% (50pc) vertically and horizontally to give me the exact center of an image file, or you place them manually with View > New Guide.
After doing that I would place the circular select from that center point using Shift and Alt (Opt) and get it more or less where I wanted it. Then change the selection into a work path.
You can use Free Transform to reshape and position that work path by selecting it in the Paths panel.
Then place your text, and if you still need to fine tune, use Free Transform again, but on the Type layer.
You could also use Free Transform to reshape the BG graphic to make it round. -
No rows returned with where number_value
Hi all,
Im using Oracle 10.2.0.1 on Windows 2000.
I got something strange here.
I have a table like:
TABLE_NAME COLUMN_NAME DATA_TYPE DATA_LENGTH DATA_PRECISION DATA_SCALE
TEST COL1 NUMBER 22 1 0when I try to perform a query like:
select * from test where col = 0this returns 0 rows.
when I do:
select * from test;
COL1
1
1
1
1
0
0
2but when a use to_number, it returns rows for zero value:
select * from test where to_number(col) = 0;
COL1
0
0somebody knows about this strange problem?
thank you very much!!!!
[]´sHi,
>>I´m trying to understand this.
Me too ;-)
SQL> create table test (col1 number);
Table created.
SQL> alter table test add constraint ck_test check (col1 in ('0','1'));
Table altered.
SQL> insert into test values (0);
1 row created.
SQL> select * from test where col1=0;
no rows selected
SQL> explain plan for select * from test where col1=0;
Explained.
SQL> set linesize 130
SQL> set pagesize 0
SQL> select * from table(dbms_xplan.display);
Plan hash value: 766971379
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 13 | 0 (0)| |
|* 1 | FILTER | | | | | |
|* 2 | TABLE ACCESS FULL| TEST | 1 | 13 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(NULL IS NOT NULL)
2 - filter("COL1"=0)
Note
- dynamic sampling used for this statement
19 rows selected.
SQL> select * from test where to_char(col1)=0;
COL1
0
SQL> explain plan for select * from test where to_char(col1)=0;
Explained.
SQL> set linesize 130
SQL> set pagesize 0
SQL> select * from table(dbms_xplan.display);
Plan hash value: 1357081020
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 13 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(TO_NUMBER(TO_CHAR("COL1"))=0)
Note
- dynamic sampling used for this statement
17 rows selected.Cheers
Legatti -
How do I return to where I left off in my contact list when texting multiple people on 5S?
If you 6 menu buttons are pointing to Tracks then select the Track and in the property inpector you can set the Menu Remote Control options. Set Menu to the button on the menu you want to jump to.
You can set this option individually for chapters in a Track also so,
HTH,
-Jake -
Whenever I switch from My Music to iTunes Store and then back to My Music, it sends me to the top of My Music instead of where I was when I switched. How can I get it to return to where I was when I switch out of and back into My Music instead of going back to the top?
Firefox will reload a page and reposition at the top if the copy in the cache has expired. However, that shouldn't happen right away.
When you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
(1) Bypass Firefox's Cache
Use Ctrl+Shift+r to reload the page fresh from the server.
Alternately, you also can clear Firefox's cache completely using:
orange Firefox button (or Tools menu) > Options > Advanced
On the Network mini-tab > Cached Web Content : "Clear Now"
If you have a large hard drive, this might take a few minutes.
(2) Remove the site's cookies (save any pending work first). While viewing a page on the site:
* right-click and choose View Page Info > Security > "View Cookies"
* Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
Then try reloading the page. Does that help?
Maybe you are looking for
-
Problem with PF_STATUS in ALV
Hi I have the following code written in my report to set PF_STATUS in ALV.But its not working call function 'REUSE_ALV_GRID_DISPLAY' exporting i_callback_program = g_repid i_callback_pf_status_set = 'PF_STATUS_SET' I
-
Some images not showing up in PDFs
Are there particular limits on what types of images can be exported to PDF and still be viewed on a mobile device? I see several PDFs where I can view the images on a desktop monitor, but not in an iPod touch. We are trying quite a few iterations of
-
I have been trying to install the new version of itunes for 2-days now. I had to uninstall the previous versions because of another issue. I have uninstalled all instances of itunes and quicktime and have downloaded the new version. When I try to run
-
I have a few issues E8 my media files (music)free ones have gone?
Basically my music or Audio files have gone? and when I click on one it's asking me for the file location...this has happened after down loading the media pack thing..about 3.6Gb I can see it in my Adobe file (programmers) but Shiite frightened to op
-
Date modified: Saturday, July -2147483642, 41221, 17:00
I have an external drive hooked up to a ruby red iMac year 2001 (Tiger 10.4.11) that's online via Aiport (using Wifi "b" flavor, neither "g" nor "n"). I am on an iMac (lamp style, year 2003 with Tiger 10.4.11) connected with Ethernet to the router. T