Splitting text column into sections
(Using Oracle 9i SQL)
I need to be able to split text which may be from 0 to 2000 bytes into sections of no more than 10 characters and assign a sequence to each. As usual, example is the best way to illustrate.
The following presents the "raw" data:
with src as (
select 'A100000' part_no,
'Short' descr
from dual
UNION ALL
select 'A100001','two words' from dual
UNION ALL
select 'A100002','Should be two lines' from dual
UNION ALL
select 'A100003','This is going to be 3' from dual
UNION ALL
select 'A100004','Oneverylongword' from dual
UNION ALL
select 'A100005','Perfectfit' from dual
UNION ALL
select 'A100006','' from dual
UNION ALL
select 'A100007','A Perfectfit but 3 lines' from dual
UNION ALL
select 'A100008','Toolongforone' from dual
UNION ALL
select 'A100009','Toolongforone too' from dual
select part_no,
descr
from src
PART_NO DESCR
A100000 Short
A100001 two words
A100002 Should be two lines
A100003 This is going to be 3
A100004 Oneverylongword
A100005 Perfectfit
A100006
A100007 A Perfectfit but 3 lines
A100008 Toolongforone
A100009 Toolongforone too
10 rows selected.What I want is this kind of thing:
PART_NO DESCR SEQ TEXT
A100000 Short 1 Short
A100001 two words 1 two words
A100002 Should be two lines 1 Should be
A100002 Should be two lines 2 two lines
A100003 This is going to be 3 1 This is
A100003 This is going to be 3 2 going to
A100003 This is going to be 3 3 be 3
A100004 Oneverylongword 1 Oneverylon
A100004 Oneverylongword 2 gword
A100005 Perfectfit 1 Perfectfit
A100006 0
A100007 A Perfectfit but 4 lines 1 A
A100007 A Perfectfit but 4 lines 2 Perfectfit
A100007 A Perfectfit but 4 lines 3 but 4
A100007 A Perfectfit but 4 lines 4 ines
A100008 Toolongforone 1 Toolongfor
A100008 Toolongforone 2 one
A100009 Toolongforone too 1 Toolongfor
A100009 Toolongforone too 2 one too
Thanks although there is a bug when the text is too big:
with src as (
select 'Alen0000' id,
'Short' str
from dual
UNION ALL
select 'Alen0001','two words' from dual
UNION ALL
select 'Alen0002','Should be two lines' from dual
UNION ALL
select 'Alen0003','This is going to be 3' from dual
UNION ALL
select 'Alen0004','Oneverylongword' from dual
UNION ALL
select 'Alen0005','Perfectfit' from dual
UNION ALL
select 'Alen0006','' from dual
UNION ALL
select 'Alen0007','A Perfectfit but 3 lines' from dual
UNION ALL
select 'Alen0008','Toolongforone' from dual
UNION ALL
select 'Alen0009','Toolongforone too' from dual
SELECT
ID, STRING
FROM
(SELECT
ID, LEVEL level#,
SUBSTR (str, INSTR (str, base, 1, LEVEL) + len,
INSTR (SUBSTR (str, INSTR (str, base, 1, LEVEL) + len, limit# + 1),
base, -1) -1) STRING,
INSTR (str, base, 1, LEVEL) + len - 1 start#,
INSTR (SUBSTR (str, INSTR (str, base, 1, LEVEL) + len, limit# + 1), base, -1)
+ INSTR (str, base, 1, LEVEL) + len - 1 end#
FROM
(SELECT
ROWNUM ID, ' ' base, ' ' || str || ' ' str, LENGTH (' ') len, 10 limit#
FROM src
CONNECT BY LEVEL <= (length (str) - length (REPLACE (str, base))) / len - 1
START WITH start# = 1
CONNECT BY PRIOR end# = start# and prior ID=ID
GROUP BY ID, level#, STRING
/ERROR at line 4:
ORA-01436: CONNECT BY loop in user data
yet is I change limit from 10 to 15 it is OK
Similar Messages
-
Splitting one column into different columns.
Hello Experts,
How do i split datetime column into different columns while doing a Select statement.
Ex:
The column "REC_CRT_TS" has data like "2014-05-08 08:23:09.0000000".The datatype of this column is "DateTime". And i want it in SELECT statement like;
SELECT
YEAR(DATETIME) YEAR,
MONTH(DATETIME) MONTH,
DATENAME(DATETIME) MONTHNAME,
DATEPART(DATETIME) WEEKNUM,
DAY(DATETIME) DATE,
DATEPART(DATETIME) HOUR
FROM TABLE_NAME;
The output should look like this;
--YEAR| MONTH | MONTHNAME| WEEKNUM | DATE | HOUR
--2014| 5 | May | 25 | 08 |08
Any suggestions please.
Thanks!
RahmanI made a very quick research and I see in this blog post
http://www.jamesserra.com/archive/2011/08/microsoft-sql-server-parallel-data-warehouse-pdw-explained/
that It also uses its own query engine and not all features of SQL
Server are supported. So, you might not be able to use all your DBA tricks. And you wouldn’t want to build a solution against SQL Server and then just hope to upsize it to Parallel Data Warehouse Edition.
So, it is quite possible that this function doesn't exist in PDW version of SQL
Server. In this case you may want to implement case based month name or do it in the client application.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Splitting one column into 4 columns
Hi,
I want to split one column into 4 columns as shown below.
parameters
PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
PanelPanel=MP12100173&YearYear=2013&Source=1&UserID=aac6440
it should be display as
panel yearyear source userid
MP01110201 2013 1 aad2779
MP12100173 2013 1 aac6440
there will be thousands of rows in the column. Can anybody help how to split it as shown.The length may very from row to row
Thanks for your help.........
BALUSUSRIHARSHAIt is working...thank u very much... I found one more issue here
PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
PanelPanel=MP11100070&Source=1&PNR=2&YearYear=2014&UserID=ddc1535
PanelPanel=MP11101276&Source=1&YearYear=2014&PNR=2&UserID=ddc1565
I found 3 kinds of formats in the same column... I didn't observe the data carefully while posting the
question..sorry about that. In this case if we need to show as
panel yearyear source
userid
MP01110201 2013 1 aad2779
MP11100070 2014 1 ddc1535
MP11101276 2014
1 ddc1565
is it possible to filter like this? Should we use any case statement in query while we have diff formats
like this?
BALUSUSRIHARSHA -
SQL Update to split 1 column into 2
I have a column in a table that holds both a city and a zip ex. Jackson 44319
I am trying to write an sql update query so that the 2 pieces of info would be split and funneled into their own respective column. For example:
Before
column name: address
Jackson 44319
After
column name:city column name: zip
Jackson 44319
Here is what I have come up with so far, but it does not work correctly.
Update Table
Set city=Parsename(Replace(address ,',','.'),2),
zip=Parsename(Replace(address ,',','.'),1)
this query basically copies all my info from the address table and puts it into the zip table, and the city table remains null. yet, nothing gets split.Does your db have a bulk loading utility? Do you have access to text manipulation tools such as awk?
If so, using them is probably a better idea than using ColdFusion. -
Split multiple columns into rows using XML
Hi Forum,
I am trying to split 2 columns that each contain values separated by semicolon into single rows. The relation between the values of the two columns is that the order in the cells corresponds to each other.
The data looks like this:
pk Manufacturer partnumber
1 Man1; Man2;Man3 PN1;PN2;PN3
2 Man4; Man2;Man5 PN4;PN5;PN6
The result should be:
pk Manufacturer partnumber
1 Man1 PN1
1 Man2 PN2
1 Man3 PN3
2 Man4 PN4
2 Man2 PN5
2 Man5 PN6
I am not sure how to format the XML to get a useful Basis for XML.value or XML.query
Any ideas?
TIA
AlexHi,
Try like this ,
DECLARE @tmp TABLE (pk INT,Manufacturer NVARCHAR(50),partnumber NVARCHAR(50))
INSERT @tmp SELECT 1,'Man1; Man2;Man3','PN1;PN2;PN3'
INSERT @tmp SELECT 2,'Man4; Man2;Man5','PN4;PN5;PN6'
SELECT * FROM @tmp
SELECT tmp2.pk pk,Manufacturer,partnumber FROM (
SELECT ROW_NUMBER()OVER(ORDER BY tmp1.pk) RN,* FROM (
SELECT pk,
LTRIM(i.value('.','varchar(100)')) Manufacturer
FROM ( SELECT pk, Manufacturer,
CONVERT(XML,'<r><n>'
+ REPLACE(Manufacturer,';', '</n><n>') + '</n></r>') AS X
FROM @Tmp) Spt
CROSS APPLY Spt.X.nodes('//*[text()]') x(i)
) tmp1 ) tmp2
JOIN
(SELECT ROW_NUMBER()OVER(ORDER BY pk) RN,* FROM (
SELECT pk,
j.value('.','varchar(100)') partnumber
FROM ( SELECT pk, partnumber,
CONVERT(XML,'<r><n>'
+ REPLACE(partnumber,';', '</n><n>') + '</n></r>') AS Y
FROM @Tmp) Spt
CROSS APPLY Spt.Y.nodes('//*[text()]') y(j)) tmp2 ) tmp3 ON tmp3.RN = tmp2.RN
sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **. -
Split 1 column into multiple columns
Hi
How can we acheive this in Sql:
Col 1
abc def ghi jkl
convert to:
Col 1
Col 2
Col 3
Col 4
abc
def
ghi
jkl
Royal ThomasThe best approach is to NOT split them out into individual columns... It violates the 1st normal form...
Under first normal form, all occurrences of a record[sic] type must contain the same number of fields[sic].
First normal form excludes variable repeating fields[sic] and groups.
The better approach is to split them into rows, in their own table, with a foreign key reference back to the table you are pulling them away from.
If you check my 1st post you'll see that I split the string with a function. That same a function can be used to populate the new table.
Something along these lines...
IF OBJECT_ID('tempdb..#BadOldDesign') IS NOT NULL
DROP TABLE #BadOldDesign;
CREATE TABLE #BadOldDesign (
ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
ListOfCodes VARCHAR(100) NOT NULL
INSERT #BadOldDesign (ListOfCodes) VALUES
('abc htr tbj yfd hjk mth'),
('bbb hyt tbj vyk hjk htd'),
('vvv nud'),
('yyy hyn tbj bdr '),
('htr htf tbj yfd hjk mko'),
('kio bhn tbj bjd hjk'),
('byd loj tbj yfd hjk cds');
SELECT * FROM #BadOldDesign bod
IF OBJECT_ID('tempdb..#ShinyNewTable') IS NOT NULL
DROP TABLE #ShinyNewTable;
SELECT
bod.ID,
sc8.ItemNumber,
sc8.Item
INTO #ShinyNewTable
FROM
#BadOldDesign bod
CROSS APPLY dbo.SplitCSVToTable8K(bod.ListOfCodes, ' ') sc8;
ALTER TABLE #ShinyNewTable ALTER COLUMN id INT NOT NULL;
GO
ALTER TABLE #ShinyNewTable ALTER COLUMN ItemNumber INT NOT NULL;
GO
ALTER TABLE #ShinyNewTable ADD CONSTRAINT pk_ShinyNewTable PRIMARY KEY CLUSTERED (ID, ItemNumber);
SELECT * FROM #ShinyNewTable snt
The dbo.SplitCSVToTable8K function that I'm using can be found here... http://www.sqlservercentral.com/articles/Tally+Table/72993/
HTH,
Jason
Jason Long -
Splitting of column into furthur subcolumn's into an ALV list
Hi All,
I've to display the data in a alv grid in Such format.
category
name
age
|--|-|
sc
st
As far as i know there is no way available to split the column headinng furthur into subheadings.
But any how if it is possible please tell me.
Note : The above displayed list is just an eaxmple there may be dynamically furthur subdivision of it's heading.
--AmitAmit,
Its not possible to merge neither the headings nor the columns as such.
Regards,
Ravi -
AppleScript Split text file into multiple files
I have large text files that I would like to break up into individual files. They are compilations of articles; I want to create a new file for each article, which begins with:
Document # of #
I don't think any other lines start with "Document" so that might be fine as a delimiter.
Also, it would be great if the new files could be named "LAT_1", "LAT_2", etc.
I found this thread:
AppleScript separating one text file into many at Paragraph break
I tried the second script by twtwtw and changed
set parsingText to "Document"
but got the following error:
error "Can’t get item 2 of {\"LAT 1985-1990 local food copy.txt\"}." number -1728 from item 2 of {"LAT 1985-1990 local food copy.txt"}
I also found this thread but it was too complicated for me to understand. Re: Split a large text file with many entries into separate files
Can anyone help me modify the script? I've been looking at this as well as Unix commands to use in Terminal, but I'm just too much of a beginner.
Any assistance is much appreciated!
TrishaHello
Here's a modified version of the script in
Split a large text file with many entries into separate files
https://discussions.apple.com/thread/5641125?tstart=0
This will split the given text by delimiter line in the form of "Document # of #" and save each chunk of text from one delimiter to the preceding line of the next delimiter in separate file named after LAT_0000.txt, where 0000 is sequential number starting at 0001.
Note that any text before the first delimiter is ignored and not saved in output file. You may select multiple input files. Existing file in the destination folder is overwritten. Input text is assumed to be in UTF-8 and each line is termitated by U+000A LINE FEED.
set ff to choose file with prompt "Choose input file(s)." with multiple selections allowed
set d to choose folder with prompt "Choose destination folder."
set args to ""
repeat with a in {d} & ff
set args to args & " " & a's POSIX path's quoted form
end repeat
do shell script "/usr/bin/perl -CSDA -w <<'EOF' - " & args & "
use strict;
sub usage () {
printf STDERR \"Usage: %s output_directory file [file ...]\\n\", $0;
exit 1;
&usage() unless @ARGV > 1;
my $outdir = shift @ARGV;
unless ( -d $outdir ) {
printf STDERR \"Not a directory: %s\\n\", $outdir;
&usage();
my $i = 0;
my ($n, $n0, $t);
while (<ARGV>) {
if ( /^ \\s* Document \\s+ [0-9]+ \\s+ of \\s+ [0-9]+ .* $/ox ) {
$n = sprintf('LAT_%04d.txt', ++$i); # e.g., LAT_0001.txt
if ( $n0 ) {
open(OUT, '>', \"$outdir/$n0\") or die $!; # overwrite
print OUT $t;
close OUT;
($n0, $t) = ($n, $_);
else {
$t .= $_;
if ( $n0 ) {
open(OUT, '>', \"$outdir/$n0\") or die $!; # overwrite
print OUT $t;
close OUT;
EOF"
Hope this may help,
H -
How do you split a column into two
I have a huge list of names that ended up in one column. For example it says "John Smith" in one column. How do I put John in one column and smith in another without having to do each one manually?
Your help is much appreciated. Thank you.PeterBreis0807 wrote:
Copy all the text into TextEdit , Pages or any other texteditor.
Select all the text and set up tabs on the ruler where you want the 2 columns to appear.
Search on the space between the "John" and "Smith" and replace it with a tab.
You can now copy and paste this into a Numbers table and it will fill the appropriate columns.
And if the entry is John Broadus WATSON you will get an odd result !
Yvan KOENIG (from FRANCE mercredi 15 juillet 2009 10:57:29) -
To split a column into multiple columns
Hi,
I have column and i want to split it into three columns as shown below given inputs and required outputs. I have written this query to get P_1, and p_2 but dont know how to get p_3.
SELECT ADDRESS,SUBSTR(ADDRESS,1, INSTR(ADDRESS,' ')-1) P_1
,SUBSTR(ADDRESS, instr(address,' ',-1)+1) P_2
FROM TT
Input:
ADDRESS
1 AVENUE OF THE AMERICAS
2 NORTH CAROLINE STREET EAST
236 TURPENTINE ROAD COOPER CREEK
REQUIRED OUTPUT
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER
Thanks in advanceIf you're on 10g or 11g you can do something like this ...
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 4 21:18:07 2008
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
column p_1 format a3
column p_2 format a10
column p_3 format a30
with data as
select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
select
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\1' ) as p_1 ,
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\3' ) as p_2 ,
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\2' ) as p_3
from
data
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER
3 rows selected.
-- or try this shorter version --
with data as
select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
select
regexp_replace( address, '^([^ ]+).*', '\1' ) as p_1 ,
regexp_replace( address, '.*?([^ ]+)$', '\1' ) as p_2 ,
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\2' ) as p_3
from
data
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER
3 rows selected.See SQL Snippets: SQL Features Tutorials - Regular Expressions if you're unfamiliar with regular expressions.
If you can't / don't want to use regular expressions then you'll need to settle for a more boring approach like this one.
with data as
select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
select
substr( address, 1, instr( address, ' ' ) - 1 ) as p_1 ,
substr( address, instr( address, ' ', - 1 ) + 1 ) as p_2 ,
substr
( address,
instr( address, ' ', + 1 ) + 1,
instr( address, ' ', - 1 ) - instr( address, ' ' ) - 1
) as p_3
from
data
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER--
Joe Fuda
SQL Snippets -
Splitting Single Column into 3 columns.
I have a column data like this
85052/123755 LAURITSEN/H HENRIK S MR
87432/119975 MORTENSEN/P PIA BUBANDT MS
73784/127530 PEDERSEN/M MORTEN H MR
88579/128347 JENSEN/M MORTEN MR
./AIRTECH STEFANSEN/P PER MR
10024/AIRTECH HOFFMANN/M MICHAEL KJUL MR
75922/128415 MOELLER/F FRANK MR
17639/128440 THOMSEN/P PETER MR
53198/127655 THYGESEN/E EBBE MR
85960/128473 ORAEINAMZADI/M MAZYAR MR
52663/128270 MAINZ/J JAN MR
17639/128440 THOMSEN/P PETER MR
27510/. HANSEN/N NILS HARLADSTED
43885/126300 LARSEN/J JOHNNI S MR
87580/125410 STEFANSEN/R RASMUS MR
63215/128445 NIELSSON/J JESPER MR
80594/123334 OLSEN/H HENRIK W MR
I need to split this into three columns
85052/123755 LAURITSEN/H HENRIK S MR
should be split as
Column1: 85052
Column2: 123755
Column3: LAURITSEN/H HENRIK S MR
but in some cases it may also be like this
./AIRTECH STEFANSEN/P PER MR
this should be split into
Column1: null
Column2: null
Column3: AIRTECH STEFANSEN/P PER MR
one more scenario is like this
27510/. HANSEN/N NILS HARLADSTED
Column1: 27510
Column2: null
Column3: HANSEN/N NILS HARLADSTED
Pls Help
Thanks
Vinoth.Based on the sample data you provided,
SQL> WITH T
2 AS (SELECT '85052/123755 LAURITSEN/H HENRIK S MR' str FROM DUAL
3 UNION ALL
4 SELECT './AIRTECH STEFANSEN/P PER MR' str FROM DUAL
5 UNION ALL
6 SELECT '10024/AIRTECH HOFFMANN/M MICHAEL KJUL MR' str FROM DUAL
7 UNION ALL
8 SELECT '27510/. HANSEN/N NILS HARLADSTED' str FROM DUAL)
9 SELECT REGEXP_REPLACE (REGEXP_SUBSTR (str, '[^/]+', 1, 1), '[^[:digit:]]') col1
10 ,REGEXP_REPLACE (REGEXP_SUBSTR (str, '[^/]+', 1, 2), '[^[:digit:]]') col2
11 ,REGEXP_SUBSTR (str, '[[:alpha:]].*', 1, 1) col3
12 FROM T;
COL1 COL2 COL3
85052 123755 LAURITSEN/H HENRIK S MR
AIRTECH STEFANSEN/P PER MR
10024 AIRTECH HOFFMANN/M MICHAEL KJUL
27510 HANSEN/N NILS HARLADSTED
SQL> G. -
Split single column into multiple column using sql /plsql
create table test (name varchar2(255);
insert into test values('DH RED 20 12/10 10 2 ');
insert into test values('PM STUD 20 15/10 20 29.55' );
insert into test values('LS MENTHOl FILTER ASC 18/70 60 240.66');
insert into test values('WINSTON WHITE CLASSIC 13 18/70 60 240.66');
My Output should be like as below in other table :
create table test_result (brand varchar2(255),packet varchar2(50),amount varchar2(25),total varchar2(25));
BRAND PACKET AMOUNT TOTAL
DH RED 20 12/10 10 2
PM STUD 20 15/10 20 29.55
LS MENTHOl FILTER ASC 18/70 60 240.66
WINSTON WHITE CLASSIC 13 18/70 60 240.66can you please help me to solve this issue
thanks in advance
Edited by: A on Apr 21, 2012 11:33 PM
Edited by: A on Apr 21, 2012 11:34 PM
Edited by: A on Apr 21, 2012 11:34 PMh4. # Database should be 10g. If version is below 10g query need to be modified as per string format.
h4. # Split string into two parts by '/'. First part contain brand + packet(1), Second part contain packet(2) + amount + total
h4. # Your brand name can be of any length.
String Format* : <Brand Name><space><packet(1)>/<packet(2)><space><amount><space><total>
SELECT name,
REGEXP_SUBSTR(first_part,'.+[[:space:]]',1,1) brand,
REGEXP_SUBSTR(first_part,'[^[:space:]]+/',1,1) || REGEXP_SUBSTR(second_part,'[^[:space:]]+[[:space:]]',1,1) packet,
REGEXP_SUBSTR(second_part,'[^[:space:]]+[[:space:]]',1,2) amount,
REGEXP_SUBSTR(second_part,'[^[:space:]]+$',1) total
FROM
(SELECT trim(name) name,
trim(substr(name,1, instr(name,'/'))) first_part,
trim(substr(name,instr(name,'/')+1)) second_part
FROM test )
{code} -
Final Cut Pro 7: Split a clip into sections so I can add part slow-motion
The questions in the question tbh. I just have a clip which i want to slow down part of but i found the only way to do this is to split the clip and then slow down the section. but i dont know how to split it?
While you're visiting the built-in manual system, look up the razor blade tool.
bogiesan -
Split the column into two based on conditions
Hello,
I have 2 tables Country and Continent.
Continent has the data like this
ID Name
1 Asia
2 Africa
3 North America
4 South America
Country has
ID Name ContinentID Population
1 China 1 2000
2 India 1 1500
3 Ethiopia 2 7500
4 United States 3 5000
I need the count of countries for each continent break into two columns based on the population. One column showing the count of countries with population <= 2000 and the other column should show the count of countries with population >2000
How can I achieve this?
Please help.
Thank youHere you go:
DECLARE @continent TABLE (ID INT, Name VARCHAR(30))
INSERT INTO @continent (ID, Name) VALUES (1, 'Asia' ),(2, 'Africa' ),(3, 'North America'),(4, 'South America')
DECLARE @country TABLE (ID INT, Name VARCHAR(30), ContinentID INT, Population INT)
INSERT INTO @country (ID, Name, ContinentID, Population) VALUES (1, 'China', 1, 2000),(2, 'India', 1, 1500),(3, 'Ethiopia', 2, 7500),(4, 'United States', 3, 5000)
SELECT COUNT(*), ct.name
FROM @country c
INNER JOIN @continent ct
ON c.ContinentID = ct.ID
GROUP BY ct.name
and for the high/low:
DECLARE @continent TABLE (ID INT, Name VARCHAR(30))
INSERT INTO @continent (ID, Name) VALUES (1, 'Asia' ),(2, 'Africa' ),(3, 'North America'),(4, 'South America')
DECLARE @country TABLE (ID INT, Name VARCHAR(30), ContinentID INT, Population INT)
INSERT INTO @country (ID, Name, ContinentID, Population) VALUES (1, 'China', 1, 2000),(2, 'India', 1, 1500),(3, 'Ethiopia', 2, 7500),(4, 'United States', 3, 5000)
;WITH popRank AS (
SELECT ROW_NUMBER() OVER (PARTITION BY ct.ID ORDER BY POPULATION DESC) AS row, ct.name AS continentName, c.name AS countryName, c.population, c.ContinentID
FROM @country c
INNER JOIN @continent ct
ON c.ContinentID = ct.ID
SELECT r.countryName AS biggestPopCountry, r.population as biggestPopCount, r1.countryName AS lowestPopCountry, r1.population as lowestPopCount
FROM popRank r
INNER JOIN popRank r1
ON r.ContinentID = r1.ContinentID
AND r1.row = (SELECT MAX(row) FROM popRank WHERE ContinentID = r.ContinentID)
AND r.row = 1 -
How to split a column into 4 sub columns of table in adf
i hav a table and i need to make a column in to 4 sub columns. ie i havae column called scheduled under the same
column i have 3 column releted to scheduled . how i make it possible
Regards
RajeshHi Rajesh,
Something like this?
<tr:column headerText="Schedules">
<tr:column headerText="Schedule A">
<tr:outputText value="#{row.bindings.ScheduleA.inputValue}"/>
</tr:column>
<tr:column headerText="Schedule B">
<tr:outputText value="#{row.bindings.ScheduleB.inputValue}"/>
</tr:column>
<tr:column headerText="Schedule C">
<tr:outputText value="#{row.bindings.ScheduleC.inputValue}"/>
</tr:column>
<tr:column headerText="Schedule D">
<tr:outputText value="#{row.bindings.ScheduleD.inputValue}"/>
</tr:column>
</tr:column>Regards,
Chan Kelwin
Maybe you are looking for
-
What exactly is in the in-app purchase in the new Garageband?
I've found that the lessons in the old version of Garageband are the same as the new one. If you have the old verison and donwload the lessons from it, you also have the lessons for the new version without paying extra. Likewise, it seems, with many
-
Working on DVDSP 4.1.2, Mac OS 10.5.4, on a MacBook Pro 2.4, 4 gigs ram, I have been building a Main Menu. There are about a dozen buttons that have motion in them from the video track they are linked too. I wanted on State 1/Normal of the button to
-
How do I set up for Wireless printing on a Mac
Hi Guys, I have purchased the HP Laser jet P1102w recently. I took the printer on a location job and used it for the first time. It was quite a soimple process of connecting the printer and MAC automatically downloaded and installed the software. A
-
What is sync speed limited by?
Assuming my line is all ok, what is sync speed limited by? The reason i ask is im told my exchange and line is rated for 2 meg (which i was syncing at around 2.5), on sppedtest was getting 2 meg download...so all is looking well...but then randomly o
-
I am trying to create weekly annoucements at our church using RevoStock 3D templates, RevoStock says I must have Adobe After Effects version 7.0 PRO or higherin order to use the templates. I can not find a version 7.0 PRO or higher.