Error while fetching nested loop output [closed] - sql

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;
/

Related

select a single unique record in a column if records are duplicate [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 8 years ago.
Improve this question
select a single unique record in a column if records are duplicate
we a class table
c_id
timing
we have records as (c_id,timing) values
1 | 3-5
2 | 5-7
3 | 3-5
4 | 7-9
5 | 9-11
6 | 11-1
7 | 7-9
we select all timing but we have 3-5 and 7-9 timing record 2 times when we select the timing it show only 1 time and other timing show like
3-5
5-7
7-9
9-11
11-1
If all you want is just the unique timing then use:
SELECT timing from class_Table group by timing
Unless there's other information you are trying to get from this query. Is there any additional info you can give us?

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

DISTINCT AND COUNT [closed]

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;

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