No Such Column in SQLite Temporary Table Statement - sql

I have two SQLite tables (companies and complaints) I'm using to calculate a ratio of HR complaints to employees, but when attempting to run the query below in DB Browser, I'm getting this error:
-- Result: no such column: complaints.hrcomplaints
Here's the SQL I'm using:
CREATE TEMPORARY TABLE newratio AS SELECT companies.uniqueID, employees, complaints.hrcomplaints,
(ROUND(hrcomplaints * 100.0 / employees, 1)*.01) AS newratio
FROM companies
ORDER BY newratio
The column type for both hrcomplaints and employees is integer. I'm not seeing any extra whitespace in the column names when viewing the DB structure.

Related

Teradata query using a large list of values in WHERE predicate

I'm attempting to query Teradata in SQL Assistant, something along the lines of
select * from
addressTable
where accountNumber in
(
'AC001',
'AC098',
'AC711',
...
)
from a list of over 100,000 accountNumbers sent to me in a file.
What I have tried
StackOverflow past questions - all seem to say that you need to insert into a temp table using a select clause from a table within the same database
Teradata doco on the link below. When I go to create table globdb.gt1, I get error 'CREATE TABLE Failed 3802: Database 'globdb' does not exist.
https://docs.teradata.com/r/Teradata-Database-SQL-Fundamentals/June-2017/Database-Objects/Tables/Global-Temporary-Tables

Query emp table in oracle 19c

make a java program that queries the inbuilt table “emp” and display the first two columns (empno using column index and ename using column name ) of all the rows.
But problem here is :
ERROR:
ORA-04043: object emp does not exist
I am using oracle 19c on windows platform and using pluggable database orclpdb user "hr".
please tell me where to find this emp table.
And second question :
Even if I manually create a new Emp table in hr user ,what will be the sql command for the given
/*
* Using
* queries the inbuilt table “emp” and
* displays the first two columns
* (empno using column index and ename using column name )
* of all the rows.
*/
just tell me the sql command only.

ORA-01792: maximum number of columns in a table or view is 1000 error while using WITH in sql

I have a query :
WITH abc AS
(
(SELECT SRC_DATA.*,
(SELECT MAX(DECODE(OBJ.AUD_ACTION_FLAG,'D',OBJ.OUPDATE_COUNT,OBJ.NUPDATE_COUNT))
FROM SMARTTRIAL_ODR_LANDING.AUD_TRIAL_DESIGN OBJ
WHERE OBJ.AUD_DATE_CHANGED BETWEEN TO_DATE('01-JAN-1900') AND (SRC_DATA.AUD_DATE_CHANGED)
AND DECODE(OBJ.AUD_ACTION_FLAG,'D',OBJ.OTRIAL_NO,OBJ.NTRIAL_NO)= DECODE(SRC_DATA.AUD_ACTION_FLAG,'D',SRC_DATA.OTRIAL_NO,SRC_DATA.NTRIAL_NO)
AND OBJ.AUD_ACTION_FLAG <> 'D'
) UPDATE_COUNT,
/***Multiple select statement like above with many other look up tables like AUD_TRIAL_DESIGN ****/
FROM SMARTTRIAL_ODR_LANDING.AUD_TRIAL SRC_DATA /***AUD_TRIAL is the base table***/
),
WITH def AS
(SELECT OBJ_DATA .*,
/***Similar statement as mentioned in above block and lookup table is AUD_OBJECTIVE***/
FROM SMARTTRIAL_ODR_LANDING.AUD_TRIAL_OBJECTIVE OBJ_DATA /***AUD_TRIAL_OBJECTIVE is the base table***/
)
----Query to select columns-----
FROM abc
LEFT JOIN def
LEFT JOIN xyz ON (column from def = column from xyz)
For the simliar structure of query written by me, following error is returned :
ORA-01792: maximum number of columns in a table or view is 1000
01792. 00000 - "maximum number of columns in a table or view is 1000"
*Cause: An attempt was made to create a table or view with more than 1000
columns, or to add more columns to a table or view which pushes
it over the maximum allowable limit of 1000. Note that unused
columns in the table are counted toward the 1000 column limit.
*Action: If the error is a result of a CREATE command, then reduce the
number of columns in the command and resubmit. If the error is
a result of an ALTER TABLE command, then there are two options:
1) If the table contained unused columns, remove them by executing
ALTER TABLE DROP UNUSED COLUMNS before adding new columns;
2) Reduce the number of columns in the command and resubmit.
Could anyone please suggest a solution
We had a similar problem (Here is an excerpt from the SR):
Creating view generates ORA-01792 maximum number of columns in a table or view is 1000
We have a new application that has a view that contains 35 columns. However, when creating it, it errors out stating that there are over 1000 columns, which is false. I will attach the view definition
Here is what Oracle said (and it did fix the problem):
Bug 19893041 : ORA-01792 HAPPEN WHEN UPDATE TO 12.1.0.2
closed as dup of
Bug 19509982 : DISABLE FIX FOR RAISING ORA-1792 BY DEFAULT.
Solution:
SQL> alter system set "_fix_control"='17376322:OFF';
Or
B. Apply patch 19509982
(no conflicts found with the attached opatch)
That may be the same issue you're encountering.

SQL Table does not exist

This is what happens:
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
Discount
Taxes
Customer
Vehicles
WorkOrder
Task
TaskPart
Employee
EmplyeeTask
WorkOrderPart
InvoiceDetails
TABLE_NAME
------------------------------
Invoice
Parts
InvoicePrimaries
14 rows selected.
SQL> select * from Discount;
select * from Discount
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
I can't access that table. I can make it work just fine in C#, but in the Oracle GUI and the SQL Command Line, I cannot select the table. (It's a personal, self made database using Oracle Express)
Because in user_tables the table names are written in upper and lower case letters. I assume that you created these tables using something like
create table "Discount" ...
Generally oracle saves tablenames in upper case letters and table names without double quotas are searched in uppercase. Therefore your
select * from Discount
searches for a table named DISCOUNT and not Discount. You have to explicitly tell oracle that you want to preserve the letter case of your table names. That is done with double quotas as well. So
select * from "Discount"
should work.

In creating a new table in SQL Server 2005

I have a table Company. Now I need to copy the contents of table Company in a new table Employee (that too while creating the Employee table). I just used the query shown below, but its showing an ERROR.
Create Table Employee as (Select * from Company)
Is there any other solution for this....?
Simply use INTO:
Select * into Employee from Company