GROUP BY and HAVING can appear in either order.
Hi,
please give me one example for the following line i found it in "19-28 Oracle Database SQL Language Reference".
If you specify both GROUP BY and HAVING, then they can appear in
either order.
yours sincerly
Hi,
944768 wrote:
that means both queries bring same result?Right; both ways produce the same results.
GROUP BY deptno
HAVING COUNT (*) > 2does exactly the same thing, just as efficiently as
HAVING COUNT (*) > 2
GROUP BY deptno
Similar Messages
-
Hi,
According to standard sql, we must have:
select ___
from ___
where ___
group by ___
having ___;
However, I tried do the query with the following order:
select ___
from ___
where ___
having ___
group by ___;
And I received the same result.
Does anybody knows the difference between those two orders? Are they always give the same result?
Thank YouAccording to the 9i documentation:
Specify GROUP BY and HAVING after the where_clause and CONNECT BY clause. If you specify both GROUP BY and HAVING, they can appear in either order.
Which you've got to admit does match your experience.
Cheers, APC -
I upgraded my MacBook Pro with Lion (but with iphoto 9.2.1) to Maverick and now I can't open iphoto and I can't update either - can anyone help please?
Download the iPhoto upgrade from the App Store. It should be free.
iWork and iLife for Mac come free with every new Mac purchase. Existing users running Mavericks can update their apps for free from the Mac App Store℠. iWork and iLife for iOS are available for free from the App Store℠ for any new device running iOS 7, and are also available as free updates for existing users. GarageBand for Mac and iOS are free for all OS X Mavericks and iOS 7 users. Additional GarageBand instruments and sounds are available for a one-time in-app purchase of $4.99 for each platform. -
I bought two HD movies and I can not get either one of them to play...help please?
What have you tried?
What happened?
Error message?
Any info? -
Use of group by and having clause
hi frnds
can anybody explain me the use of group by an having clause in select state mentHi Rohit,
1. GROUP BY f1 ... fn
2. GROUP BY (itab)
1. GROUP BY f1 ... fn
Effect
Groups database table data in a SELECT command on one line in the result set. A group is a set of lines which all have the same values in each column determined by the field descriptors f1 ... fn.
... GROUP BY f1 ... fn always requires a list in the SELECT clause. If you use field descriptors without an aggregate funciton in the SELECT clause, you must list them in the GROUP BY f1 ... fn clause.
Example
Output the number of passengers, the total weight and the average weight of luggage for all Lufthansa flights on 28.02.1995:
TABLES SBOOK.
DATA: COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
DATA: CONNID LIKE SBOOK-CONNID.
SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
INTO (CONNID, COUNT, SUM, AVG)
FROM SBOOK
WHERE
CARRID = 'LH' AND
FLDATE = '19950228'
GROUP BY CONNID.
WRITE: / CONNID, COUNT, SUM, AVG.
ENDSELECT.
Note
... GROUP BY f1 ... fn is not supported for pooled and cluster tables.
2. GROUP BY (itab)
Effect
Works like GROUP BY f1 ... fn if the internal table itab contains the list f1 ... fn as ABAP source code. The internal table itab can only have one field. This field must be of the type C and should not be more than 72 characters long. itab must be enclosed in parentheses and there should be no blanks between the parentheses and the table name.
Note
The same restrictions apply to this variant as to GROUP BY f1 ... fn.
Example
Output all Lufthansa departure points with the number of destinations:
TABLES: SPFLI.
DATA: BEGIN OF WA.
INCLUDE STRUCTURE SPFLI.
DATA: COUNT TYPE I.
DATA: END OF WA.
DATA: WA_TAB(72) TYPE C,
GTAB LIKE TABLE OF WA_TAB,
FTAB LIKE TABLE OF WA_TAB,
COUNT TYPE I.
CLEAR: GTAB, FTAB.
WA_TAB = 'COTYFROM COUNT( * ) AS COUNT'. APPEND FTAB.
APPEND WA_TAB TO FTAB.
WA_TAB = 'CITYFROM'.
APPEND WA_TAB TO GTAB.
SELECT DISTINCT (FTAB)
INTO CORRESPONDING FIELDS OF WA
FROM SPFLI
WHERE
CARRID = 'LH'
GROUP BY (GTAB).
WRITE: / WA-CITYFROM, WA-COUNT.
ENDSELECT.
Regards,
Susmitha -
Question about GROUP BY and HAVING
Good afternoon,
I have the following query which returns the desired result (set of students who take CS112 or CS114 but not both). I wanted to "condense" it into a single SELECT statement (if that is at all possible - DDL to execute the statement is provided at the end of this post):
-- is this select distinct * and its associated where clause absolutely
-- necessary to obtain the result ?
select distinct *
from (
select s.sno,
s.sname,
s.age,
sum(case when t.cno in ('CS112', 'CS114')
then 1
else 0
end)
over (partition by s.sno) as takes_either_or_both
from student s join take t
on (s.sno = t.sno)
where takes_either_or_both = 1
;The following looked reasonable but, unfortunately unsuccessful:
Window functions not allowed here (in Having Clause)
select max(s.sno),
max(s.sname),
max(s.age),
sum(case when t.cno in ('CS112', 'CS114')
then 1
else 0
end)
over (partition by s.sno) as takes_either_or_both
from student s join take t
on (s.sno = t.sno)
group by s.sno
having sum(case when t.cno in ('CS112', 'CS114')
then 1
else 0
end)
over (partition by s.sno) = 1
Invalid identifier in Having clause
select s.sno,
s.sname,
s.age,
sum(case when t.cno in ('CS112', 'CS114')
then 1
else 0
end)
over (partition by s.sno) as takes_either_or_both
from student s join take t
on (s.sno = t.sno)
group by s.sno, s.sname, s.age
having takes_either_or_both = 1
;I have searched for a document that completely defines the sequence in which the clauses are executed. I have found tidbits here and there but not something complete. I realize that my running into problems like this one is due to my lack of understanding of the sequence and the scope of the clauses that make up a statement. Because of this, I cannot even tell if it is possible to write the above query using a single select statement. Pardon my bit of frustration...
Thank you for your help,
John.
DDL follows.
/* drop any preexisting tables */
drop table student;
drop table courses;
drop table take;
/* table of students */
create table student
( sno integer,
sname varchar(10),
age integer
/* table of courses */
create table courses
( cno varchar(5),
title varchar(10),
credits integer
/* table of students and the courses they take */
create table take
( sno integer,
cno varchar(5)
insert into student values (1,'AARON',20);
insert into student values (2,'CHUCK',21);
insert into student values (3,'DOUG',20);
insert into student values (4,'MAGGIE',19);
insert into student values (5,'STEVE',22);
insert into student values (6,'JING',18);
insert into student values (7,'BRIAN',21);
insert into student values (8,'KAY',20);
insert into student values (9,'GILLIAN',20);
insert into student values (10,'CHAD',21);
insert into courses values ('CS112','PHYSICS',4);
insert into courses values ('CS113','CALCULUS',4);
insert into courses values ('CS114','HISTORY',4);
insert into take values (1,'CS112');
insert into take values (1,'CS113');
insert into take values (1,'CS114');
insert into take values (2,'CS112');
insert into take values (3,'CS112');
insert into take values (3,'CS114');
insert into take values (4,'CS112');
insert into take values (4,'CS113');
insert into take values (5,'CS113');
insert into take values (6,'CS113');
insert into take values (6,'CS114');Hi, John,
Just use the aggregate SUM function.
select s.sno,
s.sname,
s.age,
sum(case when t.cno in ('CS112', 'CS114')
then 1
else 0
end) as takes_either_or_both
from student s join take t
on (s.sno = t.sno)
GROUP BY s.sno,
s.sname,
s.age
HAVING sum(case when t.cno in ('CS112', 'CS114')
then 1
else 0
end) = 1;Analytic functions are computed after the WHERE- and HAVING clause have been applied. To use the results of an analytic fucntion in a WHERE- or HAVING clause, you have to compute it in a sub-query, and then you can use it in a WHERE- or HAVING clause of a super-query. -
Upgraded to 10.5.8 and now can't see either of my networked printers
Hello all, I just upgraded my G5 dual 2.5 to 10.5.8. I have two printers that are both connected to separate Airport Extremes. My G5 ethernet port is connected to a linksys WET11 wireless ethernet bridge, which is in turn connected to the wi-fi network of the main airport. Here is my problem. I can surf the web just fine, so clearly my G5 is seeing the Airport. However ever since upgrading to 10.5.8 I can't add either of my networked printers in the printer setup. It just doesn't see any printers. I've reset the printing in the OS (control clicking on the print prefs and resetting followed by reboot) I've rebooted both the printer and the airport separately and I've double checked that the printer is set as a shared printer in the airport admin software. My laptop (an ibook g4) also running 10.5.8, has no problem seeing both networked printers and printing to them. I'm flummoxed as to why my tower suddenly can't. (It could see both with the exact same setup running 10.4.11) Any ideas? Your help is greatly appreciated, since this is very frustrating! thanks,
-AndrewYour network setup is a little complicated. Can you explain it a little better and confirm that there's only one DHCP server in it - all devices get IP addresses from one of the Airport Extremes, for example?
It sounds like maybe you have two or more separated subnets. -
Can I send a group message and have it appear as an individual message to the recipients?
I am looking for a way to send one message to all of my work contacts without having everyone's information sent to every recipient. Is there a way to send a group message, but have the recipients of the message only see that it was from me?
I Don't believe that's possible yet unfortunately. The decision to determine group texting is on the recipients phone not on your end. So on the iPhone if the recipient has the group messaging toggled to the on position and you send out a group text the recipient will be able to see all of the people that text went to. You could ask, within your group text that they all start a new text to you instead of replying to that one because unfortunately the option to reply to sender or reply to all hasn't caught on with cell phones yet. I would love to see this change in the near future or if there is a way or a workaround hopefully someone mentions it here.
Jewell -
Find duplicate records withouyqusing group by and having
I know i can delete duplicate records using an analytic function. I don't want to delete the records, I want to look at the data to try to understand why I have duplicates. I am looking at tables that don't have unique constraints (I can't do anything about it). I have some very large tables. so I am trying to find a faster way to do this.
for example
myTable
col1 number,
col2 number,
col3 number,
col4 number,
col5 number)
My key column is col1 and col2 (it is not enforced in the database). So I want to get all the records that have duplicates on these fields and put them in a table to review. This is a standard way to do it, but it requires 2 full table scans of very large tables (many, many gigabtytes. one is 150 gbs and not partitioned), a sort, and a hash join. Even if i increase sort_area_size and hash_area_size, it takes a long time to run..
create table mydup
as
select b.*
from (select col1,col2,count(*)
from myTable
group by col1, col2
having count(*) > 1) a,
myTable b
where a.col1 = b.col1
and a.col2 = b.col2
I think there is a way to do this without a join by using rank, dense_rank, or row_number or some other way. When I google this all I get is how to "delete them". I want to analyze them a nd not delete them.create table mytable (col1 number,col2 number,col3 number,col4 number,col5 number);
insert into mytable values (1,2,3,4,5);
insert into mytable values (2,2,3,4,5);
insert into mytable values (3,2,3,4,5);
insert into mytable values (2,2,3,4,5);
insert into mytable values (1,2,3,4,5);
SQL> ed
Wrote file afiedt.buf
1 select * from mytable
2 where rowid in
3 (select rid
4 from
5 (select rowid rid,
6 row_number() over
7 (partition by
8 col1,col2
9 order by rowid) rn
10 from mytable
11 )
12 where rn <> 1
13* )
SQL> /
COL1 COL2 COL3 COL4 COL5
1 2 3 4 5
2 2 3 4 5
SQL>Regards
Girish Sharma -
I can't get any further on either device than "Add a Device".
The code in the 3 little windows is uneditable on on either device. Both the computer and the phone say "Then enter this code:" but neither one will let me enter anything.Sounds like it's hardware issue. The iPhone warranty is based in the original country of purchase. Since it was bought in Korea you will need to ship the phone to someone you know in Korea to be taken in and then they will have to ship it back to you. The cost of shipping will be at your expense.
-
I have a table having columns business_name ,sales,state,zip.
I would like to know count of businesses having sales 0-50 and
count of businesses having sales50-100, and 100-150 and so on.
can i write single query to gent count of business for all these ranges,instead of
writing seperate query for each range. If possible please tell me how?SELECT sum(case
when sales between 0 and 50 then 1
else 0
end
) sales_0_50
,sum(case
when sales between 51 and 100 then 1
else 0
end
) sales_51_100
,sum(case
when sales between 101 and 150 then 1
else 0
end
) sales_101_150
,sum(case
when sales > 150 then 1
else 0
end
) sales_over_150
FROM biz_table; -
Linking 2 drops downs and having tables appear
I need to link 2 drop downs together so that the second is dependant on the first. I also need to have a table appear when the second drop down option is selected. If they change their mind and select a different option in the 2nd drop down a different table needs to appear. Currently i have 2 drop downs that are linked so that the options in the 2nd will change but i cant link this for a table to appear? Im not great with Java or scripting.
Hi Melissa,
In the change event of 2nd DropDown you can put the following code.
var a = xfa.event.newText
if(a == 5) // Set the value that you want.
Table2.presence = "hidden";
else {
Table2.presence = "visible";
Thanks,
Bibhu. -
Assigning a picture to contact in address book and having that appear when my phone rings
Hi.....can you assign a picture to a person/contact in your address book.....and when that person calls me on my phone....their picture appears letting me know who is calling???? I don't have caller id with my package...but there must be away around this by assigning a picture of a person to that contact, ?
thanks
ShellyWelcme to the Frums!
http://supportforums.blackberry.com/rim/board/message?board.id=8300&thread.id=35224&view=by_date_asc...
Ditto Milton response.
Nurse-Berry
Follow NurseBerry08 on Twitter -
Acrobat can't find my scanner anymore. I have two and it can't find either.
Why can't Acrobat find my scanners anymore?
It would appear that Adobe's programmers are "stuck" on the idea that they need to "fix" their ICA software, rather than figuring out why their TWAIN software worked flawlessly with version 8 [Acrobat Pro], and not at all with many scanners across many computer systems. I'm running Mac OSX 10.7.5, with Acrobat Pro [11.0.09] and the problem just gets worse with each Adobe update.
-
I couldn't get my email. It kept saying can't connect to server so I deleted them and tried to save them gain. It's still saying it can't connect and won't let me saw them again. This is all on my iPhone 4S btw. Please help
Try this...go to mobile data , turn that on then scroll down till you find mail check if that mail is on.
Maybe you are looking for
-
Can no longer print from internet
About two weeks ago my printer stopped printing anything from the Internet. It will print files from Mac Word but nothing from Safari (5.1.1.0). I have tried uninstalling and reinstalling printerI reset Safari (except for passwords) The printer will
-
Master data loading - Dimension Property value incorrect
Hi, I have a dimension in BPC which has an attribute amount. When am trying to load the master data from BW, the number is truncated and displayed with a * if the number has more than 6 digits. If this is a problem with the delimited - comma - then i
-
So, I used to only have PCs in my life, so when I went to college with my first Mac laptop I knew that I was in for a learning curve. I had just authorized my Mac when I was trying to figure out how to get the songs on my 80GB iPod Classic into my mu
-
Hi, I'm having a few small problems at the moment with the internationalisation tags and was hoping that someone here could clear up something for me. I am working on a website that has to be produced in 4 languages, two of them are displaying correc
-
I had to do a system restore and lost all my bookmarks. How do I get them back?
I did not know that if I did a system restore that I would loose all my bookmarks.