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
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 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
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I want to generate a number triangle in PL/SQL like this,
If you pass 9 then it has to generate the given output.
123456789
12345678
1234567
123456
12345
1234
123
12
1
If you pass 10 then it has to generate the given output.
12345678910
123456789
12345678
1234567
123456
12345
1234
123
12
1
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
DECLARE
V VARCHAR2(20);
BEGIN
FOR I IN REVERSE 1..5
LOOP
FOR J IN 1..I
LOOP
V:=V||' '||J;
END LOOP;
DBMS_OUTPUT.PUT_LINE(V);
V:=NULL;
END LOOP;
END;
/
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
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
There is a column of Country Code and another 3 column with MEDALS GOLD,SILVER, and BRONZE
I want to Show The total of GOLD,SILVER, and BRONZE Medals they have got for each country,
Graph look like this
COUNTRY_ISOCODE PART_GOLD PART_SILVER PART_BRONZE
--------------- ---------- ----------- -----------
AUS 2 0 0
AUS 2 0 3
AUS 0 0 0
ZAF 0 0 0
ZAF 1 1 0
But i want it be like this
COUNTRY_ISOCODE PART_GOLD PART_SILVER PART_BRONZE
--------------- ---------- ----------- -----------
AUS 4 0 0
ZAF 1 1 0
Assuming you do talk about SQL (as implied by count and distinct):
select country_isocode,
sum(part_gold) as part_gold,
sum(part_silver) as part_silver,
sum(part_bronze) as part_bronze
from the_table
group by country_isocode;
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