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.
Tags: Database
Similar Questions
-
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 do I get this sql query?
Hi all
I'm using oracle 11g.
I have a table as below:
[code] create table id_test)
Identification number, name varchar2 (20)
) ;
[/ code]
And records like below:
[code]
ID NAME
1 sr
1 ds
2 sr
DS 2
3 sr
[/ code]
where I want to select only the id that have only the name as "sr."
But as I have 100 names cannot put a not in condition to check other names.
The expected result would be like:
[code]
ID NAME
3 sr
[/ code]
Concerning
Dale
Do you want to max (id) name = "SR"... Try the below
SELECT id,
name
GO (select id,
name,
ROW_NUMBER() over (ORDER BY id desc) rn
of id_test
WHERE name = 'sr')
WHERE rn = 1
OR
SELECT MAX id (id),
name
Of id_test
WHERE name = 'sr '.
GROUP BY name.
OR if you want to get the id which is only in SR, then try it out below
SELECT id,
name
Id_test A1
WHERE name = 'sr '.
AND NOT EXISTS (SELECT 1 from id_test a2
WHERE a1.id = a2.id
AND name! = « sr ») ;
Post edited by: 000000
-
Wat is the problem with this simple query?
I use 10gxe.
This is the query that does not work
Whenever I'm him running a pop-up windows is coming
and asks me to enter the bind variables... Should wat I do?
Here's a question prntscrn.
http://potupaul.webs.com/at.html
G_message VARIABLE VARCHAR2 (30)
BEGIN
: g_message: = "Œuvres of My PL/SQL block;
END;
/
G_message IMPRESSION
Edited by: user4501184 may 18, 2010 12:42 AMuse sqlplus 't's work' ng
run
cmd
sqlplus / as sysdba
G_message VARIABLE VARCHAR2 (30)
BEGIN
: g_message: = "Œuvres of My PL/SQL block;
END;
/
G_message IMPRESSIONhope this helps
Daniele -
Cannot get this hp photosmart 7550 installed on this computer why
have an hp 7550 photo phtosmart printer and I can't install it on my computer, now why. Need to print photos
have a hp 7550 photosmart photo printer can not get installed it on my computer windows 7 hp2011x why
-
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
;
-
It happens every time I go to diff. web sites he abandon the connection cannot get this return must start all over again
http://www.ehow.com/how_11385212_troubleshoot-reset-connection-Firefox.html
-
New user trying to create this simple function of Xcode
I'm a programmer windows trying to learn Xcode / swift.
How can I get this simple function to work?
He complains about the pi in the line "access to".
I hope this is enough information.
Thank you
disp_to_acceleration Func (freq: Float, disp: Float)-> {Float
Let pi = M_PI
Let accel = disp * 2 * powf (freq * pi, 2.0)
Back to accel
}
Oops error in the post "Let's accel.
-
cannot get rid of the pop up prestosavings click here for your charitable giving to purches 1.0
I googled prestosavings and it seems to be an add ON. They call it "discreet" but where is everything related to the announcement "discreet"?
This person has had a similar problem and prosecuted for a solution-
https://support.Mozilla.org/en-us/questions/939056 -
Hi, after you install Minecraft in my iMac, I get this message: "cannot start minecraft, if you run from a dmg, please drag applications and try again. I Don t know how to start the game. Thank you
So what measures through 'install '?
-
Cannot get GS110TP to work as simple as GS105E
For my work, I have to check the services through utp links in different VLANS. I used a GS105E with its function of mirror. I can connect the GS105E without any configuration of vlan and all traffic of dozens of VLAN is transparent over the switch.
Now I have to do the same on optical fiber and got a GS110TP for this but cannot operate as simple as before with the GS105E.
Now, it looks like I need to configure a large number of VLANs and the GS110TP is limited to 64 VLAN.
Does anyone know how to make similar on the GS110TP as on the GS105E?
So I understand I can't use this switch for what I want. I need to check the uplinks containing 250 + VLAN.
In addition to the effort of different configuration each time that there a limit of 64 VLANS.
Am I looking for another solution.
-
My iCloud and shared calendars has stopped working in MS Outlook today. They worked yesterday. Now, I get the error message "cannot open this series of records. The information store cannot be opened? I tried the fix standard support.
Same thing here. Looks like Windows did an automatic update during the night, and now nothing iCloud associated work (calendars, contacts, etc.)
I also noticed that the error message: "could not load file or Assembly ' MOM." Implementation ' or one of its dependencies. The system cannot find the specified file. "It started after restarting the Windows Update as well. I imagine that the two are related in the same problem to iCloud.
-
When I start my computer, I get this error message:
Windows cannot open this file: GLBD4EA.tmp
To open this file, Windows needs to know what program you want to use to open it. Windows can go online to look for automatically, or you can manually select from a list of programs installed on your computer.
What do you do?
-Use the web service to find the appropriate program
-Select a program from a list of installed programsNo selection works for me. I don't know what concerns the .tmp file, or why I need to open it.
Please help :)
Hello
Perform the following steps to remove the file from the registry.a: type regedit into the search box start and click on enter.b: Search now to the following keyHLKM\SOFTWARE\Microsoft\windows\currentversion\runthen delete the following key53E412B3-9907-4F9E-A6DC-D0106D1D72CImportant: This section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information
However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click on the number below to view the article in the Microsoft Knowledge Base:Hope this information helps. -
Hi, I get this error msg everytime that restarts my system (with Windows Vista), pls help:
Windows cannot install the important updates:
(1) KB978542(2) KB971644
(3) KB974470(And Norton) McAfee applications are known to not uninstall (or upgraded) themselves.
1. download the McAfee Consumer Product Removal, save it to your desktop tool:http://download.mcafee.com/products/licensed/cust_support_patches/MCPR.exe
2. close all open applications (that is, anything with an icon on the taskbar).
3. right click on the file that you saved in #1 above and select run as administrator to run the utility. DO TAP not your keyboard until the race ends, then restart.
4. for good measure, reset IE now by http://support.microsoft.com/kb/923737
5. now to reset Windows Update by...
How to reset the Windows Update components?
[Access KB971058 via Internet Explorer (32-bit) only; Run the difficulty in the default and aggressive modes]
http://support.Microsoft.com/kb/9710586. restart once again & test.
~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft
-
Pop Up-
The program cannot start because MSVCR80.dll is missing on your computer.
Your response-Try reinstalling the program to fix this problem.Question-Where can I get this program to download?Hello
If the problem is with iTunes, uninstall everything according to the instructions from Apple:
«Remove and reinstall iTunes, QuickTime, and other software components for XP»
http://support.Apple.com/kb/ht1925
It is also the same list of what to remove what is in the link above from Apple:
http://pcsupport.about.com/od/findbyerrormessage/a/MSVCR80-DLL-not-found-missing-error.htm
Or try this program to remove it:
http://www.revouninstaller.com/revo_uninstaller_free_download.html
"Resolution of problems with iTunes for Windows Update"
https://discussions.Apple.com/docs/doc-6562
If the advice already given does not, please contact Apple for assistance.
"Not to install iTunes or QuickTime for Windows"
http://support.Apple.com/kb/HT1926
"iTunes support-how to use iTunes.
http://www.Apple.com/support/iTunes/
"Contact iTunes Support.
http://www.Apple.com/support/iTunes/contact/
Or ask in the community Apple iTunes:
https://discussions.Apple.com/community/iTunes
____________________________________________
If the problem is not with iTunes, there is other information about this error on the link pcsupport.
See you soon.
Maybe you are looking for
-
Please can you let me know when iOS 9.3 will be fixed? Safari does not. Internet links in the emails does not.
-
HP Pavilion dv6820ee notebook PC
I have HP Pavilion dv6820ee notebook PC My laptop does not connect to the data source or to another monitor screen for windows 7 has been installed I tried to download the nvidia driver, but still it won't work, now, the system can identify the 2 scr
-
Satellite Pro M70: Need of original discs and says Configfree switch is off
1. I can't find all the original disks for my M70 Sat.Pro - of the suggestions. 2 Configfree is installed and running, but it keeps informing me that my wireless switch is turned off. It is of course. Any suggestions please
-
Hello I have this problem. My user account has been corrupted. I couldn't connect to my account, if used administrator. When looked at in the event viewer, I saw these ID 1500 and 1508. 1508: Windows could not load the registry. This is often caused
-
Hello I have windows xp, a few months when I start my laptop, all the information that was on the c drive were gonne the computer started with a temporary profile and not with mine. I did nothing, I continue to use it with the temp profile. After a w