database - 带有文本值的 SQL 插入查询
问题描述
有没有办法可以将它插入数据库?
INSERT INTO Bill_Table (Patient_ID, [Med/Room], Bill, [Paid/UnPaid])
VALUES (13, 'Room ID' + (SELECT Room_ID
FROM Room_Master
WHERE [Room_No.] = 2),
(SELECT Price
FROM Room_Type
WHERE Room_Type = 'Semi-Private'), 'UnPaid');
在值上的“13”之后,有一个字符串“房间 ID”加上选定的“房间 ID”,但是当我执行这个时,只有插入在桌子上的房间 ID 有办法我可以把字符串文本加上选择查询
解决方案
使用insert . . . select
:
insert Into Bill_Table (Patient_ID, [Med/Room], Bill,[Paid/UnPaid])
Select 13, concat('Room ID', rm.Room_ID), rt.price, 'UnPaid'
from Room_Master rm left join
Room_Type rt
on rt.Room_Type = 'Semi-Private'
where rm.[Room_No.] = 2;
在 SQLite 中,您将使用 concat 运算符:
Insert Into Bill_Table (Patient_ID, [Med/Room], Bill,[Paid/UnPaid])
Select 13, 'Room ID' || rm.Room_ID, rt.price, 'UnPaid'
from Room_Master rm left join
Room_Type rt
on rt.Room_Type = 'Semi-Private'
where rm.[Room_No.] = 2;
推荐阅读
- ios - 使用类似操作的演示文稿 iOS 13
- arrays - Apache Spark 数组模糊比较
- ssh - GitLab 警告:未受保护的私钥文件!'/dev/fd/63' 的权限 0660 太开放
- javascript - 在 Angular 8 中使用 http.get() 调用在 iframe 中显示报告
- ios - 通过 Facebook 应用程序重定向和登录时,IOS Facebook 登录不返回结果
- sql-server - 将数据列表从一个表插入到另一个表asp.net mvc
- firefox - Firefox 更改请求标头键的大小写?
- python - Python如何控制键盘输入
- javascript - 我的应用程序每次尝试使用 app.use 时都会崩溃
- c# - 如何 JSON 序列化实体类?