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 print the 1 to 10 numbers based on table.
Table1
A
null
outout is
1
2
3
4
.
.
10
I have a table that table contains only one record...using this table i want to print 1 to 10 numbers please tell me
I written like this...is there any alternate way to write this
select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 from table1;
or
select generate_series(1,10) from table1;
Because your question is almost devoid of useful information, I don't feel bad simply presenting a link to the docs. Take a look at generate_series()
http://www.postgresql.org/docs/current/static/functions-srf.html
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.
Improve this question
I have one table:
id
created_at
author
1
02.02.2020
manager
2
02.02.2020
client
3
02.02.2020
manager
I want to get result like below, and date sorted:
date
manager
client
02.02.2020
2
1
03.02.2020
5
3
I tried:
SELECT created_at::date, count(id) AS manager FROM orders where author = 'manager' GROUP BY created_at::date
union
SELECT created_at::date, count(id) AS client FROM orders where author = 'client' GROUP BY created_at::date
And I got:
date
manager
03.02.2020
2
02.02.2020
5
You don't need a union, this can be done in a single query using a filtered aggregate:
select created_at::date,
count(*) filter (where author = 'manager') as managers,
count(*) filter (where author = 'client') as clients
from orders
group by created_at::date
order by created_at::date
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 am new to PostgreSQL. We have given an activity to perform FULL JOIN, LEFT JOIN, AND RIGHT JOIN. I have an answer but I am not sure if it is right. I need some help to correct me.
These are the questions and my answers.
Perform a FULL JOIN on staff and staff_ph TABLE WHERE region_id is 8 AND sort from the highest salary to the lowest salary.
SELECT *
FROM staff FULL JOIN staff_ph
ON staff.id = staff_ph.id
WHERE staff.region_id = 8
ORDER BY staff.salary DESC;
Perform a LEFT JOIN on staff and staff_ph TABLE WHERE region_id is 8 AND sort by last_name.
SELECT *
FROM staff LEFT JOIN staff_ph
ON staff.id = staff_ph.id
WHERE staff.region_id = 8
ORDER BY staff.last_name DESC;
Perform a RIGHT JOIN on staff and staff_ph TABLE WHERE region_id is 8 AND sort by gender.
SELECT *
FROM staff RIGHT JOIN staff_ph
ON staff.id = staff_ph.id
WHERE staff.region_id = 8
ORDER BY staff.gender DESC;
Your FULL JOIN and RIGHT JOIN don't make much sense, since you then filter out the rows where staff.region_id was fabricated as NULL. On the other hand, it seems to be the question, not your answer, that is to blame for this. Maybe the intention was for that condition to go in the ON, not the WHERE.
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 combine distinct column of an one table, I want a column wise distinct.
SELECT ALT_SRC_HOST FROM ATABLE WHERE ALT_SRC_HOST IS NOT null
UNION
SELECT SOURCE_IP AS SOURCE_IP FROM ATABLE WHERE SOURCE_IP IS NOT null
output is coming, in one column. I want the output is in two column
expected output
ALT_SRC_HOST SOURCE_IP
- 10.262.737.21
1.34.34.112
Not sure why you want it in a single SQL but this is an option
select distinct ALT_SRC_HOST as col1 , NULL as col2
from ATABLE
union all
select distinct NULL as col1 , SOURCE_IP as col2
from ATABLE
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 7 years ago.
Improve this question
INSERT INTO EMP_COMPANY(ename,cname,salary,jdate) VALUES
('ANIL','ACC',1500.00,'01-MAY-89'),
........
('AMOL','ACC',1000.00,'17-MAR-95');
Error: ORA-00933: SQL command not properly ended .
what is missing in syntax ?
You cannot multiple records like the way you are doing. You can try like this:
INSERT INTO EMP_COMPANY(ename,cname,salary,jdate)
select 'ANIL','ACC',1500.00,'01-MAY-89' from dual
union all
select 'SHANKAR','TATA',2000.00,'10-MAY-90' from dual
union all
select 'JAYA','CMC',1800.00,'7-JULY-91' from dual
union all
select 'SUNIL','CMC',1700.00,'1-JAN-88' from dual
union all
select 'VIJAY','TATA',5000.00,'3-JAN-88' from dual
union all
select 'PRAKASH','TATA',3000.00,'27-MAY-89' from dual
There is one more option to use INSERT ALL like this:
INSERT ALL
INTO EMP_COMPANY (ename,cname,salary,jdate) VALUES ('ANIL','ACC',1500.00,'01-MAY-89')
INTO EMP_COMPANY (ename,cname,salary,jdate) VALUES ('SHANKAR','TATA',2000.00,'10-MAY-90')
INTO EMP_COMPANY (ename,cname,salary,jdate) VALUES ('JAYA','CMC',1800.00,'7-JULY-91')
...........
SELECT 1 FROM DUAL;
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
I have the following query which is generating the error message
Msg 209, Level 16, State 1, Line 4 Ambiguous column name 'p_id'
Below is the offending query.
SELECT *
from (select playerperform.p_id,player.first_name, SUM (playerperform.score)as totalgoal, RANK() OVER(ORDER BY SUM(playerperform.score)DESC) Rnk
from playerperform,player
Group by p_id
)as a
WHERE Rnk = 1
Clearly you have a p_id column in both playerperform and player.
At the very minimum, change:
GROUP BY p_id
To
GROUP BY playerperform.p_id
It also seems suspicious that you are performing an implicit CROSS JOIN:
FROM playerperform,player
I suspect that should be an INNER JOIN with some condition, such as
FROM dbo.playerperform INNER JOIN dbo.player
ON playerperform.p_id = player.p_id
As an aside, p_id is a terrible name for a column...