由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 谁能帮我看看这个Insert语句要怎么改一下?
相关主题
菜鸟问题,急A rookie's query question
sql 题目求助问个sql/ ssis的问题 谢谢!
请教一个query 优化的问题(filter keyword)一个oracle performance 的问题。
请教一个SQL的问题高手请进
sort two same tables SQL but different resultsany group function reutrn null if there is null value?
SQL copy a table into a new table and add a new column请问sql 有条件性的select columns
SQL select one value column for each distinct value another (转载)如何除去duplicate rows?
sql query help请教一个sql问题
相关话题的讨论汇总
话题: patientid话题: apptinfo话题: insert话题: select话题: doctorid
进入Database版参与讨论
1 (共1页)
I******0
发帖数: 182
1
题目是:Create a new appointment record in the ApptInfo table for a patient
that does not have an existing appointment.
我这样写的:
insert into ApptInfo(ApptNumber,apptdate,appttime,copay,ApptNotes,DoctorID)
VALUES (10006,01-04-2013,'09:30AM',$10,
select patientid from patient
where patientid not in(select patientid from ApptInfo)
我感觉问题是,倒数第二个select的结果不唯一,其结果有两个patientid
不知道要怎么改,谁能帮忙看看啊,晚上要交作业了,谢谢啊
c*****d
发帖数: 6045
2
没看懂,你这是一个Insert语句?
s**********o
发帖数: 14359
3
你的ApptNotes和DoctorID对patientid,
有点驴唇不对马嘴啊
I******0
发帖数: 182
4
不好意思啊,写错了。。那个apptnotes和DoctorID应该是一个常量,我漏了。
patientid是要通过select赋值的
我刚才问了同学,实际上patientid也是自己写个满足那个条件的常量上去就行了,所
以事情变简单了
不过我还是想知道,如果patientid需要select赋值怎么弄,在select出来的值有两个
的情况下

【在 s**********o 的大作中提到】
: 你的ApptNotes和DoctorID对patientid,
: 有点驴唇不对马嘴啊

w*****m
发帖数: 20421
5
insert targetTable
(col1, col2, patientID)
select
'1', '2' , patientID
from
patientTable
I******0
发帖数: 182
6
但是patientid有两个值,‘1’ ‘2’只是一个值啊

【在 w*****m 的大作中提到】
: insert targetTable
: (col1, col2, patientID)
: select
: '1', '2' , patientID
: from
: patientTable

w*****m
发帖数: 20421
7
自动填充了

【在 I******0 的大作中提到】
: 但是patientid有两个值,‘1’ ‘2’只是一个值啊
I******0
发帖数: 182
8
填的啥?
假如select出来的结果是 A B
刚才那个语句出来就是
col1 col2 col3
1 2 A
? ? B
这样吗?

【在 w*****m 的大作中提到】
: 自动填充了
s********e
发帖数: 893
9
col1 col2 col3
1 2 A
1 2 B
你用数据试一下就明白了。
w*****m
发帖数: 20421
10
当然是
col1 col2 col3
1 2 A
1 2 B

【在 I******0 的大作中提到】
: 填的啥?
: 假如select出来的结果是 A B
: 刚才那个语句出来就是
: col1 col2 col3
: 1 2 A
: ? ? B
: 这样吗?

I******0
发帖数: 182
11
懂了!谢谢!

【在 w*****m 的大作中提到】
: 当然是
: col1 col2 col3
: 1 2 A
: 1 2 B

O******t
发帖数: 214
12
改成这样就可以了:
insert into ApptInfo(ApptNumber,apptdate,appttime,copay,ApptNotes,DoctorID)
select 10006,01-04-2013,'09:30AM',$10,patientid from patient
where patientid not in(select patientid from ApptInfo)
1 (共1页)
进入Database版参与讨论
相关主题
请教一个sql问题sort two same tables SQL but different results
mysql mapping and insert questionSQL copy a table into a new table and add a new column
How to split a column into several rows?SQL select one value column for each distinct value another (转载)
请教一个SQL Server的面试题sql query help
菜鸟问题,急A rookie's query question
sql 题目求助问个sql/ ssis的问题 谢谢!
请教一个query 优化的问题(filter keyword)一个oracle performance 的问题。
请教一个SQL的问题高手请进
相关话题的讨论汇总
话题: patientid话题: apptinfo话题: insert话题: select话题: doctorid