Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a table test as the following
Contract date_prolog hours
-------------------------------
No 20
Yes 24/02/2014 10
No 30
No 10
How can I get this results ?
Contract date_prolog hours
-------------------------------
No 24/02/2014 20
No 24/02/2014 30
No 24/02/2014 10
select contract,
(select date_prolog from test where contract = 'yes') as date_prolog,
hours
from test
where contract = 'no'
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
Count of players who have scored within 500 runs of the leader from particular country. For example if from India A scores 1500 runs then how many players have scored more than 1000 runs.
I have run this code but this is not giving me my desired result.
select COUNT( [Player ] )as no_of_players,country from [dbo].[Sheet1$]
where runs >=
All (select max(runs)-500 from [dbo].[Sheet1$] group by country )
group by country
You can use a window function for this
SELECT
COUNT(*) AS no_of_players,
country
FROM (
SELECT *,
MAX(runs) OVER (PARTITION BY country) AS MaxRuns
FROM [dbo].[Sheet1$] s1
) s1
WHERE runs >= MaxRuns - 500;
Note that COUNT(nonNullValue) is the same as COUNT(*) or COUNT(1)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have the following table and need the following result with join based on username
Query
select
iif(count(*)>1, min(ID), max(right([User], 1))) ID,
[User],
iif(count(*)>1, concat('Total: (', cast(count(*) as varchar(12)), ')'), max(replace([Text], 'Text', 'Texto'))) [Text]
from
MyTable
group by
[User]
order by 1;
Results
ID User Text
1 User01 Total: (3)
2 User2 Texto 4
3 User3 Texto 5
6 User04 Total: (2)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to Substring the string which is delimited
ABC/123/DEF
I want in
ABC in 1st column
123 in 2nd Column
DEF in 3rd Column
If your database in sql server you can try this:
declare #t table (name varchar(50))
insert into #t values ('ABC/123/DEF')
select PARSENAME(replace(name,'/','.'),3),PARSENAME(replace(name,'/','.'),2) , PARSENAME(replace(name,'/','.'),1) from #t
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a column-based table like this:
And I need to convert it to a row-based table like this:
Any help would be appreciated.
I think you need an UNPIVOT -
SELECT OrgID, Property, DataValue
FROM (SELECT OrgID, Property, DataValue
FROM YOUR_TABLE
UNPIVOT
(
DataValue FOR Property IN (ExtensionDigits
,StartExtension
,LastUsedExtension
,Server1IP
,Server2IP
,ServerPort
,IsFunctionOn
,VolumeDecibel)
) unpvt) temp
WHERE DataValue IS NOT NULL;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I would like ask if this is possible in any database. Lets say there's one column on my database that has a content like this:
-----------------
|columname |
-----------------
| roan,joan,keith|
------------------
If I do a select query, can I just display roan from that field?
Thanks,
MSSQL version of Mark answer:
SELECT SUBSTRING(columnname, 1, CHARINDEX(',', columnname, 1) - 1) FROM testtable;
Oracle solution:
select substr(columnname,1,instr(columnname,',')-1) from testtable;