Perform Function on 1 Column Table in Oracle [closed] - sql

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 4 years ago.
Improve this question
I have a table with 1 column:
id
1
2
3
4
5
6
7
8
9
and I want the following output:
11
22
33
41
52
63
71
82
93
I am using Oracle.

you can try like below using case when
select case when (id*11)<=33 then (id*11)
when (id*11)>33 and (id*11)<70 then (id*11)-3
else (id*11)-6 end as col
from your_table
demo link
output
COL
11
22
33
41
52
63
71
82
93

Related

Use awk to replace value from column A with value from column B [closed]

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 2 years ago.
Improve this question
I'm very new to coding so I am here seeking some help. I have the table below, and I need to do as follow:
Every time that
[All_SNPs]<[Informative_SNPs]
I need to replace negative numbers or number=0 in [All_SNPs] with the values in [Informative_SNPs]. I have tried with awk but I can't get my head around this. Thank you if you can help.
Input
ID Informative_SNPs All_SNPs
1 13 0
2 29 -27
3 15 18
4 10 0
5 11 -850
6 25 37
Output
ID Informative_SNPs All_SNPs
1 13 13
2 29 29
3 15 18
4 10 10
5 11 11
6 25 37
awk 'NR>1 && ($3<=0 || $3<$2) {$3=$2}1' file
Output:
ID Informative_SNPs All_SNPs
1 13 13
2 29 29
3 15 18
4 10 10
5 11 11
6 25 37

Exclude vice-versa entries from result set using sql query [closed]

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
Let suppose there four entries in table as shown below.I want only Row 1 and 2 in resultset.
The vice versa case of 1 and 2 in Row 3 and 4 should be excluded. Please suggest a query for that
Pk Col1 Col2 Col3 Col4
1 A B 20 30
2 E D 40 50
3 B A 20 30
4 D E 40 50
WHERE Col1 < Col2 immediately comes to mind. Actually, that would give you rows 1 and 4, but I presume that's good enough for yuor purposes.

query for selecting distinct names and count names in sql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my table 2 columns are there. Name and Marks. Something like this.
Name Marks
---------- -----------
AAA 50
BBB 48
CCC 54
AAA 52
DDD 55
BBB 60
AAA 66
I need to retrieve from the table something like below
Name No.of.attempts Max Mark
------- ---------------- ------------
AAA 3 66
BBB 2 60
CCC 1 54
DDD 1 55
You should do like:
select name,count(name) as no_of_attempts,max(marks)
from table_name
group by name
fddle demo here
you can do it like this
select name,COUNT(name) as nameCount,MAX(markes) as marks from #abc group by name

Get count of two column in access 2007 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
TblAquestion:
AQcode(pk)|AQdescribe
---------------------------------
1 do you want to continue?
2 what ..........?
3 this is a ..........
4 my name is a ali?
TblUserResult:
ID(pk)|AQcode_fk|Result
-----------------------
100 1 1
101 1 0
102 1 0
103 1 0
104 1 1
105 2 1
106 2 0
107 3 1
108 3 1
109 3 1
110 3 0
111 4 1
OutPut:
ResultYes is count of result where '1'
ResultNo is count of result where '0'
AQcode|AQdescribe |CountResultYes|CountResultNo
---------------------------------------------------------------
1 do you want to continue? 2 3
2 what ..........? 1 1
3 this is a .......... 3 1
4 my name is a ali? 1 0
SQL command?
select q.AQcode, q.AQdescribe,
sum(IIF(r.Result = 1, 1, 0)) as CountResultYes,
sum(IIF(r.Result = 0, 1, 0)) as CountResultNo
from TblAquestion q
left join TblUserResult r on r.AQcode_fk = q.AQcode
group by q.AQcode, q.AQdescribe
select aqcode,aqdescribe,sum(Cno),sum(Cyes) from
(
select aqcode,aqdescribe,'0' as Cno,count(result) as Cyes
from TblAquestion aq,TblUserResult r
where aq.aqcode=r.aqcode and r.result='1'
group by aqcode,aqdescribe
Union
select aqcode,aqdescribe,count(result) as Cno,'0' as Cyes
from TblAquestion aq,TblUserResult r
where aq.aqcode=r.aqcode and r.result='0'
group by aqcode,aqdescribe
)
group by aqcode,aqdescribe

Oracle SQL grouping [closed]

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 am getting records as below:
PERIOD LABEL1 LABEL2 LABEL3 LABEL4
-----------------------------------
1 12
1 14
1 11
2 10
2 09
and so on..
I want it like below:
PERIOD LABEL1 LABEL2 LABEL3 LABEL4
-----------------------------------
1 12 14 11
2 10 09
Hope its clear.
If you only have positive values, you can use a mix of nvl and max:
select period,
max(nvl(label1, 0)) label1,
max(nvl(label2, 0)) label2,
max(nvl(label3, 0)) label3,
max(nvl(label4, 0)) label4
from my_table
group by period;