How to write this Simple query?
Select * from student
where
(select count (first_name) of student) > 1;
Basically I want a list of student table where the counties of first names are more than 1. However he shows me the output for
Select * from student;
any suggestions?
Hello
2776946 wrote:
Select * from student
where
(select count (first_name) of student) > 1;
Basically I want a list of student table where the counties of first names are more than 1. However he shows me the output for
Select * from student;
any suggestions?
Think about it. The subquery tells you the number of rows in all of the table have a first name. It will always tell you the number of rows in all of the table name. You don't want to know how many rows in the table have a name, you want to know how many rows in the table have the same name.
One way to do is a correlated subquery:
Select *.
student m-m is for hand query
where)
SELECT count (*)
student s-s is for the subquery
where s.first_name = m.first_name
) > 1
;
Tags: Database
Similar Questions
-
How to write a simple select query to get the data of the table as an XML.
How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select queryselect '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' from temp_table where id_num BETWEEN 1 AND 10;
without using XMLGEN, XMLQUERY or any other packages built and function?I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.
What is wrong with him?
At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:SQL> create or replace function my_url_escape (url in varchar2) 2 return varchar2 3 deterministic 4 is 5 begin 6 return utl_url.escape(url, false, 'AL32UTF8'); 7 end; 8 / Function created SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual; MY_URL_ESCAPE('HTTP://SOME.URI -------------------------------------------------------------------------------- http://some.uri.com/param?lang=fr&text=contr%C3%B4le
-
No idea how to write this query
Hi, My Data is as below
DocNum doc_date type of amount
1154 15 November 11 232501.5 invoice
200206 4 November 11 - 243672.64 credit memo
Note flow 111 5 November 555.22 11
Output must be
DocNum doc_date amount Type AmountDR AmountCR
1154 232501.5 15 November 11 Bill 232501.5
Note credit 200206 4 November 11 - 243672.64 - 243672.64
Note flow 111 5 November 555.22 11 555.22
If the amount is > 0, then it must be displayed in the value of the amount to be AmountDR
If amount < 0 then it must be displayed in the value of the sum amount CR
Can help how to write this querywith sample_table as ( select 1154 Docnum,date '2011-11-15' doc_date,232501.5 Amount,'Invoice' type from dual union all select 200206,date '2011-11-04',-243672.64,'Credit Memo' from dual union all select 111,date '2011-11-05',555.22,'Debit Memo' from dual ) select Docnum, doc_date, Amount, type, case when Amount >= 0 then Amount end AmountDR, case when Amount < 0 then Amount end AmountCR from sample_table / DOCNUM DOC_DATE AMOUNT TYPE AMOUNTDR AMOUNTCR ---------- --------- ---------- ----------- ---------- ---------- 1154 15-NOV-11 232501.5 Invoice 232501.5 200206 04-NOV-11 -243672.64 Credit Memo -243672.64 111 05-NOV-11 555.22 Debit Memo 555.22 SQL>
SY.
-
How to achieve this simple effect?
How to achieve this simple effect?
Hi guys,.
I just want to know what do you call the effect which the corners of the screen is blurred and darker, and how can we achieve?
See the video in this link www.youtube.com/watch?v=lHj83FRR11s.
Thank you in advance!
Use a solid layer of the color of your choice then add a mask and change his pen:
The effects coming from the photograph is called vignetting or vignnete
Another way is to add a bright spot and animated, but its more difficult, I hope it works
-
How to write the select query for it
Hello
I had an html form and the area I drop down and he needs to select several values in the drop-down box. When I select multiple values then I have to write the query to SQL select statement.
When I try to write the select statement and trying to run I get the error message.
Select * from Table
where emo_no = '1,2,3 '.
That's how I write the query please suggest me how to write the query to select several values in the drop-down box.
Thank you
Use the keyword sql 'in '. If you don't know how, I've heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.
-
How to write this query in the hierarchy
Hi gurus,
Really need your help on this query. Thank you very much in advance.
SELECT t1.key as root_key , (SELECT t2.unit_id AS unit_id level-1 AS level , t2.name, t2.creator FROM tab t2 START WITH t2.unit_id = t1.unit_id -----check each node as root CONNECT BY prior t2.unit_id = t2.parent_unit_id ) t1.name as parent_unit_name FROM tab t1
I'll write a query of the hierarchy as above, and that EACH line (node, totally more than 10200) is checked as root node to see how many sheets are accessible for her... It must be implemented in a single query.
I know inline query should NOT return multiple rows or multiple columns, but the inline elements are necessary and can certainly be made in a correct solution.
(env):
Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production
PL/SQL Release 12.1.0.2.0
)
Test data:
select 1 as unit_id, null as parent_organization_unit_id, 'U1' as name from dual union all select 2, 1, 'U2' FROM DUAL UNION ALL SELECT 3, NULL, 'U3' FROM DUAL UNION ALL SELECT 4, 3, 'U4' FROM DUAL UNION ALL SELECT 5, 2, 'U5' FROM DUAL UNION ALL SELECT 6, 5, 'U6' FROM DUAL UNION ALL SELECT 7, 6, 'U7' FROM DUAL UNION ALL SELECT 8, 5, 'U8' FROM DUAL UNION ALL SELECT 9, 5, 'U9' FROM DUAL;
Final result should be like this
key unit_id, level, name, parent_name 1 1 0 u1 u1 1 2 1 u2 u1 1 5 2 u5 u1 1 6 3 u6 u1 1 7 4 u7 u1 1 8 3 u8 u1 1 9 3 u9 u1 2 2 0 u2 u2 2 5 1 u5 u2 2 6 2 u6 u2 2 7 3 u7 u2 2 8 2 u8 u2 2 9 2 u9 u2
Don't know how get you your output, it does not match your data...
with tab as)
Select 1 as unit_id, null as parent_organization_unit_id 'U1' as the name of double
Union of all the
Select 2, 1, 'U2' FROM DUAL
UNION ALL
SELECT 3, NULL, 'U3' FROM DUAL
UNION ALL
SELECT 4, 3, 'U4' FROM DUAL
UNION ALL
SELECT 5, 2, 'U5' OF THE DOUBLE
UNION ALL
SELECT 6, 5, 'U6' OF THE DOUBLE
UNION ALL
SELECT 7, 6, "U7" OF THE DOUBLE
UNION ALL
SELECT 8, 5, 'U8' FROM DUAL
UNION ALL
9. SELECT, 5, 'U9' FROM DUAL
)
Select dense_rank() key (order by connect_by_root unit_id), unit_id, level - 1 as 'LEVEL', connect_by_root name root_parent_name
t tab
Start with parent_organization_unit_id is null
Connect prior unit_id = parent_organization_unit_id
KEY UNIT_ID LEVEL ROOT_PARENT_NAME 1 1 0 "U1". 1 2 1 "U1". 1 5 2 "U1". 1 6 3 "U1". 1 7 4 "U1". 1 8 3 "U1". 1 9 3 "U1". 2 3 0 "U3". 2 4 1 "U3". -
How to make the simple query for this scenario... ?
Hello:
Dummy table provided for simplicity.
It's my database table (Table_A)
Date1 | Plane1 | Category | Duration | Fees
01/01/2011 | A | Gold | 5. 2
01/01/2011 | C | Money | 4. 11
01/01/2011 | B | Gold | 6. 2
01/01/2011 | D | Gold | 2. 4
01/01/2011 | B | Gold | 3. 5
01/01/2011 | A | Money | 4. 8
01/01/2011 | B | Gold | 1. 3
I need to write a query to get the result below:
Date1 | Plane1 | Sum_Duration | Sum_Charge | Sum_Gold_Duration | Sum_Gold_Charge | Sum_Silver_Duration | Sum_Silver_Charge
01/01/2011 | A | 9. 10. 5. 2. 4. 8
01/01/2011 | B | 10. 10. 10. 10. 0 | 0
01/01/2011 | C | 4. 11. 0 | 0 | 4. 11
01/01/2011 | D | 2. 4. 2. 4. 0 | 0
This query will provide the 1st four columns:
SELECT Date1,
base1,
Sum (Duration) Sum_Duration,
Sum (load) Sum_Charge
FROM TABLE_A
GROUP BY date1, rarateplan
But I need to know how to get the rest of the columns (i.e. Summary according to categories; from 5 to 8 columns)? Is this can be done in a single query without writing subqueries?
Please let me know, (with code), the best way.
Thank you-
TanvirUse like this:
SELECT Date1,
base1,
Sum (Duration) Sum_Duration,
Sum (load) Sum_Charge,
SUM (decode(Category,'Gold',duration,0)) Sum_Gold_Duration,
SUM (decode(Category,'Gold',charge,0)) Sum_Gold_charge,
SUM (decode(Category,'Silver',duration,0)) Sum_Silver_Duration,
SUM (decode(Category,'Silver',charge,0)) Sum_Silver_charge
FROM TABLE_A
GROUP BY date1, rarateplanPublished by: SANT007 on August 11, 2011 11:04
-
How to write this query?
Hi people,
I need to get a query in which a set of records, I get ONLY those which previous registry has a field with a value to this topic. Other values, the field can contain are not necessary.
I know that sounds easy but... I can't get it.
So, for Oracle 10 g 2... Here's my query:
SELECT a.person_id, a.person_status, a.message_id, a.order_id
OF t_HR one
WHERE a.person_status = "rejected".
AND a.id >
(SELECT max (b.id)
OF t_HR b
WHERE b.person_id = a.person_id
and b.order_id = a.order_id
AND b.person_status! "revised =".
B.ID AND < a.id)
ORDER BY desc a.id
Let me explain:
1 - HR table is a table of people. These people has serveral STATUS.
2 - ID is a sequential (each www.voyages-sncf.com has a different identification number).
3 - the application must get THAT all people "rejected".
4. - However, (subquery) I need ONLY those that previous register (the second register) holds a status of "OK". If the person holds a "revised" status he's not, he should be the next register (the third)
5.-L' ORDER ID DESC, so is the first register must have a STATUS = "rejected" and the second a 'OK '. IF the second register = "revised", then the third register must be 'OK '. And I need this query.
HOW DO?
My problem: the subquery gives you previous register of the same guy, but... it does not give you the value of the State, I need, which is 'OK '.
I tried to add to the subquery...
SELECT max (b.id)
OF mod_human_resource b
WHERE b.person_id = a.person_id
and b.order_id = a.order_id
AND b.person_status = 'OK '.
AND b.id < a.id
... but if I have 5 records of that person, the first is "rejected", the second is "accepted", the third is 'new' and the fourth is 'OK'... the subquery gives you the 4th register and which is not correct for me, it must be only the second one (prior to the first State registry).
I need to be a query, because I need to use it on a MERGER for a DWH.
If there is another way (function, or even a procedure) to make the MERGER rather than with a request, which would be ok too. I am poor DWH knowledge.
Thanks in advance.
Hello
So, you need to know if a line is the 'first' line, and you should also know what is the 'next' status, (even the 'first' and 'next' are already defined). This sounds like a job for analytical functions. ROW_NUMBER can tell you if a line is first or not, and LEAD can tell you what a value on the next row.
Since you post CREATE TABLE and INSERT statements for your own table, I'll use the table scott.emp to illustrate.
Consider these data from scott.emp:
SELECT DeptNo
ename
work
FROM scott.emp
ORDER BY deptno
ename DESC
;
Output:
DEPTNO ENAME JOB
---------- ---------- ---------
10 MILLER CLERK
PRESIDENT OF KING 10
MANAGER 10 CLARK
20 SMITH CLERK
ANALYST SCOTT 20
20 JONES MANAGER
20 FORD ANALYST
20 ADAMS CLERK
30 WARD SALESMAN
SELLER OF 30 TURNER
30 MARTIN SALESMAN
30 JAMES CLERK
MANAGER BLAKE 30
30 ALLEN SALESMAN
Now, let's say we want only who know the departments where the forefront (in order descending ename) a job = 'CLERK', and the following line (also in descending by ename order) = "ANALYST" job, and we want to know the ename of the first row. In other words, the correct output is:
DEPTNO ENAME
---------- ----------
20 SMITH
Note that deptno = 10 is not included, even if the first task is to "CLERK." that was because the second job in deptno = 10 is the "PRESIDENT", not "ANALYST."
Here's a way to get these results:
WITH got_analytics AS
(
SELECT ename, deptno, job
ROW_NUMBER () OVER (PARTITION BY deptno
ORDER BY ename DESC
) AS r_num
LEAD (employment) OVER (PARTITION BY deptno
ORDER BY ename DESC
) AS next_job
FROM scott.emp
)
SELECT deptno, ename
OF got_analytics
WHERE r_num = 1
AND job = 'CLERK '.
AND next_job = 'ANALYST '.
;
I hope that answers your question.
If this isn't the case, then, as Dan (and the FAQ forum) said, post CREATE TABLE and INSERT statements for some sample data and the exact results you want from these data.
Post your query, based on the one I have posted more top and ponit out where he gets results.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
How to write this query procedure of ina
IF ((drapeau = ' n ') OR (flag = 'F') OR (FLAG =' WAS))
) THEN
SELECT CUSTOMER_ID, BUSINESS_PASSCODE, LOG ON TO V_CUSTOMER_ID, V_BUSINESS_PASSCODE, V_LOG OF THE CUSTOMER
WHERE V_BUSINESS_PASSCODE AND V_CUSTOMER_ID = & ID = & CODE AND
V_LOG IN('Y')
SO I HAVE TO RETURN THE ISP (OF TYPE VARCHAR) CAN YOU TELL HOW DOMake values flag, id, code as a parameter and an output parameter. You can have any number f settings if you want to return the results of the query.
as
create procedure (identification number, varchar2, varcahr2, out returnvalue flag code varchar2)
as
Start
-your code---
--
IF ((drapeau = ' n ') OR (flag = 'F') OR (FLAG =' WAS))
) THEN
SELECT CUSTOMER_ID, BUSINESS_PASSCODE, LOG ON TO V_CUSTOMER_ID, V_BUSINESS_PASSCODE, V_LOG OF THE CUSTOMER
WHERE V_CUSTOMER_ID = ID AND CODE = V_BUSINESS_PASSCODE AND
V_LOG IN('Y');
returnValue =; -
How can I write this GREP query correctly (CS4)
Hello.
I have a, uh, interesting problem. I got a HUGE page layout document. copy typed in word... and have ' cleaned every regular:
-to - and multi-retourne to the simple and so on.
However, the editor has throughout the copy (by effect? LOL) decided to single space the letters of the words randomly in the text as follows:
It is a E x a m p l e, of what he has done and is a massive p r o b l e m / e h a d a, c e h!
Ok... I try to work on the proper GREP but have so far failed. What I need, is to find any space white between two simple letters and replace it with, well, to remove them. I'm into hysteria with myself as it seems so simple and yet I can not understand it.
So, here I am enlisting the help of the GREP Boffins out there.
Thank you sincerely
Grant
It would be: search
(? <><\w) (?="\w\">)
replacing it with nothing - assuming that these spaces, as Peter points out. It really could be followed as well. It's (I think) so a style German emphasis to the space of words (but not as big as a set of 'regular' space).
You'd also better to check than if there are really just words at random, otherwise you will lose focus. If you want to mark the words with a character style, you cannot use the above GREP. Interestingly, I can not write a single GREP that removes the spaces and add a character style to the text at a time... But you can use the GREP
\<\w( \w)+\="">
with a character style in the replace with formatting field to mark any text with a style, and then remove the outdoor areas.\w(>\w)> -
Cannot get this simple query!
Hi guys,.
There is this requirement easy to write a query that selects many columns in a table, but grouped on 3 columns in the same table.
Table Str:
C11 col2 col3 col4 col5 col6 col7 col8 col9 col10
Mandatory:
Group By: Col9, col10
Columns to select: C11 col2 col3 col4 col5 col6 col7 col8
I know there is something simple that I'm missing.
any help will be appreciated.
Thank you!Hello
What produces the output you asked for the data that you have posted:
SELECT MIN (col1) , MIN (col2) , MIN (col3) , MIN (col4) , MIN (col5) , MIN (col6) , MIN (col7) , MIN (col8) , col9 , col10 FROM str GROUP BY col9 , col10 ;
If the fact
WITH got_rnum AS ( SELECT str.* , ROW_NUMBER () OVER ( PARTITION BY col9 , col10 ORDER BY col1 , col2 , col3 , col4 , col5 , col6 , col7 , col8 ) AS rnum FROM str ) SELECT col1 , col2 , col3 , col4 , col5 , col6 , col7 , col8 , col9 , col10 FROM got_rnum WHERE rnum = 1 ;
With the sample data that you posted both queries produce the same results.
With other data, both queries will produce different results. -
Hello
on 11.2.0.4
I have two tables:
creation scripts are attached.
And I wrote a query to search for the students in which all their friends are in different qualities of themselves. Return the students names and ranks.
Here's my query and it works fine. But can it be written better? More effectively?
Select friend f, h1 highschooler, f.id1, h1.name, h1.grade, f.id2, h2.name, h2.grade
H2 highschooler where h1.id = f.id1 and h2.id = f.id2 and h1.grade <>h2.grade and f.id1 not in
(by selecting f1.id1 in friend f1, h3 highschooler,
highschooler h4 where h3.id = f1.id1 and h4.id = f1.id2 and h3.grade = h4.grade)
Thank you and best regards.
Step has)
count(*) over(partition by id1) cnt
It counts how many ID2 are there in each ID1
Step B)
count(decode(h.grade, h1.grade, null, 1)) over(partition by id1) f1
This does 2 things
Step 1
decode(h.grade, h1.grade, null, 1)
If grade ID1 is equal to the rank of ID2 return NULL otherwise if its different 1 return
Note: COUNTY does not have the value NULL. This is the reason for return null.
Step 2
count(
) over(partition by id1) f1 This is essentially considered how ID2 can have a different category than for each ID1 ID1
When we filter for step A is equal to step B, then it will give ID1 which all ID2 are in a different category
-
help me with this simple query
Hi, I have reached the results by querying the table twice. so, how can I get the results by hitting the table only once.
version 10g
with t as (select 100 parent , 1 child , 'Y' flag from dual union all select 100 parent , 2 child , 'N' flag from dual union all select 100 parent , 3 child , 'N' flag from dual union all select 100 parent , 4 child , 'N' flag from dual union all select 100 parent , 5 child , 'Y' flag from dual union all select 100 parent , 6 child , 'N' flag from dual union all select 100 parent , 7 child , 'N' flag from dual union all select 100 parent , 8 child , 'Y' flag from dual union all select 100 parent , 9 child , 'N' flag from dual) select * from t where parent in ( select parent from t where child = 1) and flag = 'N' order by child;
Hello
Here's one way:
WITH got_good_cnt AS ( SELECT t.* , SUM (CASE WHEN child = 1 THEN 1 END) OVER (PARTITION BY parent) AS good_cnt FROM t ) SELECT * -- or list all columns except good_cnt FROM got_good_cnt WHERE good_cnt >= 1 AND flag = 'N' ORDER BY child ;
The best way may depend on your data, for example, the columns that are unique.
Each line in your sample data has the same value for parent. Is this the best game of test data?
-
How to make this simple sql run faster?
Here is a very simple sql, but it takes too long to finish as an hour or more, and the problem is in the table. It's a huge table with 17660025 lines.
In addition, upd_dt is indexed.
Execution plan seems to be no problem: (is 9i, and I do not think that it would not perform better if the UNIQUE HASH is used instead of SORT UNIQUE)select distinct (dstn_type) from ims_ets_prty_msge where ims_ets_prty_msge.upd_dt > sysdate - 30;
Here is some info on the table----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 78 | 1409 | | 1 | SORT UNIQUE | | 6 | 78 | 1409 | | 2 | TABLE ACCESS BY INDEX ROWID| IMS_ETS_PRTY_MSGE | 856K| 10M| 10 | |* 3 | INDEX RANGE SCAN | IMS_ETS_PRTY_MSGE_INDX5 | 154K| | 2 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - access("IMS_ETS_PRTY_MSGE"."UPD_DT">SYSDATE@!-30) Note: cpu costing is off
The thing is that we must make it run faster.NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN 17129540 455259 622 502 455278 188
And all I can think is to create a bitmap on dstn_type (low cardinality) index and partition the table using upd_dt;
So my question would be is anyway that we can get a better response time without having to make that kind of change?
Or is this kind of change really help?
Any thoughts would be appreciated!
Thank youHave you thought about putting an index on (upd_dt, dstn_type)?
With the query you posted, and this index, it should be possible to use a full scan of the index, no visit to the table at all.
A bitmap index would not be a good idea, if it is an OLTP application / table.
-
How to write this trigger or is there another way?
Hello guys,.
I have a problem when I write my trigger. I want to achieve the following functions:
1. when the table generated ID automatically, then insert 'this ID' in table B.
2. after 'the ID' insert into table B, insert 'B_ID' of table table_A B.
In order to reach no. 1, there's my table A trigger code:
create or replace TRIGGER "bi_A"
front Insert the 'table_A'
for each row
Start
if : new . "ID" is null then
Select "A_SEQ" .nextval into : new . "ID" de double ;
end if ;
Insert into table_B(B_ID) values(:new.ID);
end ;
He still has the error ORA-06550, and I don't know what the problem is.
And I've always struggled with function no. 2, I think I can write another trigger belong to table B?
Thank you very much
Leila
Is the first array actually named table_A (case included)? If this is not the case, remove the quotes around the name.
create or replace TRIGGER bi_A
before inserting on table_A
for each line
Start
If: new.ID "is then null
Select A_SEQ.nextval in: double new.ID;
end if;
insert into table_B (B_ID) values(:new.ID);
end;
Maybe you are looking for
-
Magic mouse, not scroll after sleep
My magic mouse stopped scrolling when I wake my MacBook to sleep 2016. I use El Capitan 10.11.5. The only way to restore full functionality of the mouse is by restarting the computer. I watched a lot of historic messages with similar problems, but
-
Prefer not to go to the Chrome browser.
-
How can I get the search function when I right click?
I recently ran an update. Now, I don't have the function "search" when I right-click. I've used it widely and would really like the option to return. I had to uninstall certain things when I ran the update, because I didn't want the search engine or
-
Mail to delete messages from the trash on iMac
Mail is deleting messages to my trash folder despite me selecting 'Store on the server' and "Never permanently delete" in the menu of the mailbox behavior for how to deal with deleted messages. I checked the settings on my iMac, iPad and iPhone and
-
LaserJet M277n: Cannot scan from Mac
I just bought a LaserJet M277n and connected to my home network. I can print from my MacBook. I can copy the printer. I can't scan. I downloaded the HP EasyScan software, but that does not work either. For the Capture of Image Mac software and the Ea