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
Related
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'
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
What's causing this error?
Schema Creation Failed: ORA-00922: missing or invalid option
.........................
CREATE TABLE suppliers
(
sid int,
sname varchar(20),
address varchar(30)
)
CREATE TABLE product
(
pid int,
pname varchar(20),
color varchar(30)
)
CREATE TABLE catalog
(
sid int,
pid int,
cost int
)
INSERT INTO suppliers
(sid, sname,address)
VALUES
(1, "name1","address1"),
(2, "name2","address2");
SQL Fiddle
Also, your INSERT statement will probably fail in Oracle (though this is not the reason why you are getting ORA-00922)
Change it to:
INSERT ALL
INTO suppliers(sid, sname,address) VALUES (1, 'name1','address1')
INTO suppliers(sid, sname,address) VALUES (2, 'name2','address2')
SELECT * 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
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
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 8 years ago.
Improve this question
I am very new to this. I have created this table and I had no problems doing it:
CREATE TABLE [dbo].[Urban_Rail] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Country] VARCHAR (50) NOT NULL,
[City] VARCHAR (50) NOT NULL,
[Type] VARCHAR (50) NOT NULL,
[Gauge] NCHAR (10) NULL,
[Year] NCHAR (10) NULL,
[Status] VARCHAR (50) NULL,
[Notes] VARCHAR (500) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Now I am trying to fill in few thousand rows of data using this statement:
INSERT INTO Urban_Rail ('Id','Country','City','Type','Gauge','Year','Status','Notes') VALUES ('','Algeria','Algiers','Metro','1435','2011','Open','');
INSERT INTO Urban_Rail ('Id','Country','City','Type','Gauge','Year','Status','Notes') VALUES ('','Algeria','Algiers','Tram','1435','2011','Open','');
INSERT INTO Urban_Rail ('Id','Country','City','Type','Gauge','Year','Status','Notes') VALUES ('','Algeria','Batna','Tram','','','Planned','');
But I get errors saying that the name of each column is not valid. That does not look true to me. I am wondering if it has something to do with the Id instead which is an auto increment identity which I have left without value in my query. What am I doing wrong here? Some help will be appreciated.
Either remove the ID from the Insert (as it is an Identity) or if you want specific ID's turn Identity_Insert on before running the insert and off again afterwards.
SET IDENTITY_INSERT [dbo].[Urban_Rail] ON
INSERT INTO Urban_Rail (Id,Country,City,Type,Gauge,Year,Status,Notes) VALUES (1,'Algeria','Algiers','Metro','1435','2011','Open','');
SET IDENTITY_INSERT [dbo].[Urban_Rail] OFF
An IDENTITY column should not be included in the INSERT statement. It will automatically populate with the next value.
The column "ID" is an identity column and you're not allowed to insert it since the database assigns it. Take it off the column name and values list in your inserts.
If you DO need to insert the identity column, you can use
SET IDENTITY_INSERT <table> ON
But am guessing you don't need that since your ID's look blank.
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 8 years ago.
Improve this question
I want to design table for patient prescription it contains pat_id, date and more than one prescription prescribed by doctor
How to do this?
Give me a sample query to create table
This isn't really a good quetion and is a very likely candidate for someone down voting it.
Look here for an example schema
http://www.databaseanswers.org/data_models/patient_care/index.htm
Possible this be helpful for you -
CREATE TABLE dbo.Patient
(
PacientID INT IDENTITY(1,1) PRIMARY KEY
, FirstName VARCHAR(30)
, LastName VARCHAR(30)
)
GO
CREATE TABLE dbo.PatientPrescription
(
ID INT IDENTITY(1,1) PRIMARY KEY
, PacientID INT
, DoctorID INT
, [Descritpion] VARCHAR(500)
)
GO
CREATE TABLE dbo.Doctor
(
DoctorID INT IDENTITY(1,1) PRIMARY KEY
, FirstName VARCHAR(30)
, LastName VARCHAR(30)
)
GO