simple SQL query not working (emp,dept) [closed] - sql

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
the database contains the famous Oracle simple tables (dept,emp)
CREATE TABLE DEPT (
DEPTNO NUMBER(2) NOT NULL,
DNAME CHAR(14),
LOC CHAR(13));
CREATE TABLE EMP (
EMPNO NUMBER(4) NOT NULL,
ENAME CHAR(10),
JOB CHAR(9),
MGR NUMBER(4) ,
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2) NOT NULL );
Question : Find the total of Commissions for Employees according to different jobs (including 0 )
how it should be done ?

SELECT JOB, SUM(NVL(COMM,0)) AS TOTAL_COMM
FROM
EMP
GROUP BY JOB

Here I try to get job wise Commission of Employee...
Select JOB, sum(ISNULL(comm,0)) from Emp
Group by Job

Related

ORA-00907: missing right parenthesis showing again and again [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
Improve this question
Please help me to rectify the error, i have checked all the parenthesis.
CREATE TABLE employee
(
Fname varchar2(15),
Minit char(1),
Lname varchar(15) NOT NULL,
Ssn char(9) NOT NULL,
Bdate date(7),
Address varchar2(32),
Sex char(1),
Salary number(22),
Super_ssn char(9),
Dno number(22),
CONSTRAINT s_con PRIMARY KEY (Super_ssn)
);
Sql does not parameterize its DATE datatype. Thus use Bdate date instead of Bdate date(7).

SQL missing parenthesis when creating a table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 12 months ago.
Improve this question
I'm trying to create a table for a college project, but when I run my code it tells me I am missing a left parenthesis, and I simply cannot see where.
please help code is below
create table booking (
booking_id number
, booking_ref varchar2
, booking_date date
, passenger_id number
, travel_class_code varchar2
, flight_id number
, airplane_id varchar2 compound key
, booking_status_id varchar2 compound key
, ticket_type_code varchar2
, payment_method varchar2
);
You need sizes on the VARCHAR2 data types and compound key is not valid.
create table booking (
booking_id number
, booking_ref varchar2(1)
, booking_date date
, passenger_id number
, travel_class_code varchar2(1)
, flight_id number
, airplane_id varchar2(1)
, booking_status_id varchar2(1)
, ticket_type_code varchar2(1)
, payment_method varchar2(1)
, CONSTRAINT BOOKING__PK PRIMARY KEY (airplane_id, booking_status_id)
);

I am trying to extract only date value from Oracle's SYSDATE but my query is giving me ORA-02290: check constraint violated [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I want to insert current date into my record, First I executed this query successfully.
insert into Member values (1, 'Richa Sharma', 'Pune', TO_DATE('10-Dec-05', 'DD-MM-YY'), 'Lifetime', '25000', 5, 50);
Then while executing the following query I'm getting the above error code.
insert into Member values (2, 'Garima Sen', 'Pune', SYSDATE, 'Annual', 100, 3, NULL);
EDIT: This is the query I used to create table.
create table Member (Member_Id number(5),
Member_Name varchar2(30),
Member_Address varchar2(50),
Acc_Open_Date date,
Membership_Type varchar2(20),
Fees_Paid number(6),
Max_Books_Allowed number(2),
Penalty_Amount number(7,2),
PRIMARY KEY(Member_Id),
CHECK (Membership_Type IN ('Lifetime',' Annual', 'Half Yearly',' Quarterly')));
Your check constraint has a leading space in ' Annual' change to 'Annual'

Oracle Error: ERROR at line 3: ORA-00904: "ALLERGY"."PATIENTID": invalid identifier [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am having some difficulties with Oracle and Inner Joins:
I am trying to do the following "List patientID and ages of patients who are allergic to tree nuts.
I have set up the following query:
SELECT patientID, age
2 FROM PATIENT
3 JOIN Allergy on patient.patientID=allergy.patientID
4 WHERE Allergy ='Tree Nuts';
JOIN Allergy on patient.patientID=allergy.patientID
*
ERROR at line 3:
ORA-00904: "ALLERGY"."PATIENTID": invalid identifier
THE DDL for patient and allergy are as follows:
CREATE TABLE Patient
(patientID NUMBER NOT NULL,
patientMRN VARCHAR2(30) NOT NULL,
lastName VARCHAR2(30),
firstName VARCHAR2(30),
age NUMBER,
gender VARCHAR2(10),
street VARCHAR2(60),
city VARCHAR2(60),
state VARCHAR2(30),
zip VARCHAR2(15),
CONSTRAINT patient_PK PRIMARY KEY (patientID));
CREATE TABLE Allergy
(allergyID NUMBER NOT NULL,
allergyName VARCHAR2(60) NOT NULL,
type VARCHAR2(30),
CONSTRAINT allergy_PK PRIMARY KEY (allergyID));
CREATE TABLE PatientAllergy
(
patientID NUMBER NOT NULL,
allergyID NUMBER NOT NULL,
notedDate DATE,
severity VARCHAR2(30),
CONSTRAINT patientallergy_PK PRIMARY KEY (patientID, allergyID),
CONSTRAINT patientallergy_FK1 FOREIGN KEY (patientID)
REFERENCES Patient(patientID) ON DELETE CASCADE,
CONSTRAINT patientallergy_FK2 FOREIGN KEY(allergyID)
REFERENCES Allergy(allergyID) ON DELETE CASCADE
)
I am not sure what I am doing to obtain this error.
I tried this query:
SELECT patientID, age
FROM Patient, PatientAllergy
WHERE patient.patientID=patientallergy.patientID AND Allergy = 'Tree Nuts';
I am still getting an error of: ERROR at line 4: ORA-00904: "ALLERGY": invalid identifier
You're missing a table in your query and not qualifying the column name in your WHERE clause correctly. Table aliases also make your query more readable. The below query should work for you:
SELECT p.patientID, p.age
FROM patient p
JOIN patientallergy pa ON p.patientid = pa.patientid
JOIN allergy a ON a.allergyid = pa.allergyid
WHERE a.allergyname = 'Tree Nuts'
The error is pretty clear, you're using a column [patientID] that doesn't exist in the table Allergy.
Your table Allergy only have the following columns (if I refer to your script):
allergyID
allergyName
type
Tell me if I'm wrong but it seems to be the reason of your problem.

SELECT TOP 1 for each reference id [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
These are my tables simplified..
person
( id [int],
surname [varchar] (30),
ref [int],
)
episode
(
id [int],
ref [int],
typeId [int],
startDate [datetime]
)
type
(
typeId [int],
typeName [varchar]
)
I want to select all the people who have more than 1 episode and the oldest episode started after 1 Jan 2013. I tried using Row_Number and partition but i'm using Sql Server 2005 and it didn't like Row_Number().
use:
having count(*)>1
and min(startDate) >'1 Jan 2013'
Edited: Below comment is right