Query failed: column "requireddate" of relation "orders" does not exist - columnsorting

INSERT INTO "meenakamesh/demo_repo"."orders"
(orderid, employeeid, shipvia, freight, requireddate,
shippeddate, orderdate, shippostalcode, shipcountry, shipname, shipaddress, shipcity,
shipregion, customerid)
VALUES
(10270, 1, 1, '136.54','1996-08-29','1996-08-02','1996-08-01', '87110', 'Spain', 'Wartian Herkku',
'4933 Jamesville Rd.','Madrid','MY', 'WARTH');
This is the message I am seeing. Can anyone please help me? I haeve the table created in postgresql,but the message says does not exist

Related

Trying to update a field in Oracle based on a select statement - getting subquery returns more than one row error

I am trying to update a field on a table the query needs to get the value from a 2nd table and use that to get the data from a 3rd table. I keep getting the "ORA-01427: single-row subquery returns more than one row" Any help is appreciated.
update ord_detail set cuser1 = (select c.email from contact c,ord_detail m join orders o on o.ID = m.orders_ID where c.email is not null)
where EXISTS (select email from contact,orders where orders.contact_id2 = contact.id)
Since you did not provide further information like the results of your sub selects, it's not 100% clear what exactly is your problem. You should check those results and if this does not answer your question, please provide the details.
My guess is that this sub query will give multiple rows because you are missing a join from the table "contact" to one of the other tables:
select c.email from contact c,ord_detail m
join orders o on o.ID = m.orders_ID where c.email is not null
Therefore, this sub query will always lead to many rows as result unless the table "contact" contains one row only whose column email is not null.

Insert into Select (Invalid identifier Error)

I have one Table called Andamio (the destiny table), with these columns:
CODTIPOLOCALIZACION
TXTNOMBRE
CODLOCALIZACION
CODCENTRO
CODPUBLICO
TXTDESCRIPCION
And another one called Centro (the origin one), with these columns:
CODCENTRO
CODPARKING
TXTPARKING
I want to fill all the rows with the same values in the first two columns:
CODTIPOLOCALIZACION = 2 for all
TXTNOMBRE = "Park" for all
The third column comes from an Automatic Sequence: 'MySeq_seq'
CODLOCALIZACION = MySeq_seq.NEXTVAL
And the last three columns have to be the same from the origin table "Centro" but with the condition that there is no other row in the destiny table "Andamio" with the same values of CODCENTRO and CODPUBLICO equals to CODCENTRO and CODPARKING.
INSERT INTO ANDAMIO
(CODTIPOLOCALIZACION, TXTNOMBRE, CODLOCALIZACION, CODCENTRO, CODPUBLICO,
TXT_DESCRIPCION)
SELECT '2', 'Park', MySeq_seq.NEXTVAL, Datos.CODCENTRO, Datos.CODPARKING, Datos.TXTPARKING
FROM (SELECT CODCENTRO, CODPARKING, TXTPARKING FROM CENTRO centrop
WHERE (centrop.CODCENTRO <> ANDAMIO.CODCENTRO
AND centrop.CODPARKING <> ANDAMIO.CODPUBLICO)) Datos
I have tried these INSERT INTO sequence with many variations [using INSERT INTO table VALUES ('2', 'Park', SELECT(...))] and many others...
I always get the Invalid Identifier as Oracle claims there is no column called CODPUBLICO in table Andamio, but it exists indeed.
Any help would be appreciated.
Thanks!
You're getting that error because you're referencing the andamio columns in the select part of the insert statement without also having referenced the andamio table in the from clause.
I suspect a not exists clause would give you what you're after, eg:
insert into andamio (codtipolocalizacion,
txtnombre,
codlocalizacion,
codcentro,
codpublico,
txt_descripcion)
select '2',
'Park',
myseq_seq.nextval,
datos.codcentro,
datos.codparking,
datos.txtparking
from (select codcentro, codparking, txtparking
from centro cen
where not exists (select null
from andamio an
where cen.codcentro = an.codcentro
and cen.codparking = an.codpublico) datos;

ORA-00904: invalid column name but I am using the correct column name

Can someone see where I am going wrong in the below query? I am getting the error message that the GROUP BY column doesn't exist, but it clearly does as I see that column name in the output when I don't use the GROUP BY.
SELECT
(SELECT customer_address.post_code FROM customer_address WHERE customer_address.address_type = 0 AND customer_address.customer_no = orders.customer_no) postcode, SUM(orders.order_no) orders
FROM
orders, customer_address
WHERE
orders.delivery_date = '27-MAY-15'
GROUP BY
postcode;
The answer is: You cannot use an alias name in GROUP BY.
So:
GROUP BY (SELECT customer_address.post_code ...);
Or:
select postcode, sum(order_no)
from
(
SELECT
(SELECT customer_address.post_code FROM customer_address WHERE customer_address.address_type = 0 AND customer_address.customer_no = orders.customer_no) postcode,
orders.order_no
FROM orders, customer_address
WHERE orders.delivery_date = '27-MAY-15'
)
GROUP BY postcode;
EDIT:
However, your query seems wrong. Why do you cross-join orders and customer_address? By mistake I guess. Use explicit joins (INNER JOIN customer_address ON ...), when using joins to avoid such errors. But here I guess you'd just have to remove , customer_address.
Then why do you add order numbers? That doesn't seem to make sense.

Calculating age/tenure in HiveQL

I'm using the below code to calculate tenure/customer age using datediff
select user_id, datediff('2014-09-30', to_date(date_joined)) as tenure_days
from users_table
group by user_id
Error
Error: Invalid column reference date_joined
Any help here would be highly appreciated!
There is no need for grouping here. Try bellow:
select distinct user_id, datediff('2014-09-30', to_date(date_joined)) as tenure_days
from users_table

rails postgreSQL cannot get this query to work (SUM, Group Order)

This query work when I try it in SQLite:
Transaction.where(:paid => true).select("created_at, SUM(amount) amount").group("DATE(created_at)").order('created_at')
But when I run it with postgreSQL it doesn'y work.
Heres the error message:
ActiveRecord::StatementInvalid: PGError: ERROR: column "transactions.created_at" must appear in the GROUP BY clause or be used in an aggregate function : SELECT created_at, SUM(amount) as amount FROM "transactions" WHERE ("transactions"."paid" = 't') GROUP BY DATE(created_at) ORDER BY created_at
Anyone who can help me?
Thanks in advance
You have to either use DATE(created_at) in the select clause, or use created_at in the group by clause.
You're selecting created_at, sum(amount), ordering by created_at, but are grouping by date(created_at). The latter will disallow the use of anything but the grouped by fields and aggregates except in the join/where clause.
To fix, either group by created_at, or select and order by date(created_at) instead of created_at.

Resources