what is getting wrong with query ? [closed] - oracle10g

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;

Related

Is it more efficient to bind parameters or use excluded in an upsert query? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 days ago.
Improve this question
I have a table I need to write an upsert statement for. Since I'm using Go the query kinda looks like this:
INSERT
INTO
my_table(
col1,
col2
)
VALUES (
$1,
$2
)ON
CONFLICT(col1) DO
UPDATE
SET
col2 = $2
I'm just wondering if there's any benefit to instead use the following query:
INSERT
INTO
my_table(
col1,
col2
)
VALUES (
$1,
$2
)ON
CONFLICT(col1) DO
UPDATE
SET
col2 = EXCLUDED.col2
Thanks in advance!

Postgresql how to use union for two selects in the same table? [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 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

How to execute a PostgreSQL with "WITH" statement? [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 1 year ago.
Improve this question
I need to execute a query with WITH statement. If I run it, my WITH data shows error. This is my sample query please guide me to execute it.
with
x1_fields as
(SELECT
x1.id as x_id,
x1.created_time as x_created,
sum(x1.value) as x_sum
FROM
xxxx1 x1
INNER JOIN xxxx2 x2 ON x2.id = x1.id
INNER JOIN xxxx3 x3 ON x3.id = x2.id
WHERE
x1.customer = 'microsoft'
GROUP BY
x1.id,
x1.created_time
)
SELECT
y.id as final_id,
x_t.sum as final_sum
FROM
yyyy as y
left join x1_fields as x_t on x_t.x_id = y.id
where
y.customer = 'microsoft'
and y.id = '123456'
I have try to run this query in DBeaver but I can't run this. But it works in SSRS. I need to check such queries in some SQL software and debug it. Please give me some instructions to solve this.
Since we don't know your database and table structure, we cannot find an error which might occure because of wrong relation names or something.
However: Syntax error is the , character after the WITH clause (before the final SELECT). You have to remove it.

Combine the distinct column of same table in db2 [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 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

print the 1 to 10 numbers using Table [closed]

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