SQL函数AT列 [英] Sql Function AT column

查看:417
本文介绍了SQL函数AT列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了两个表
表1> RoomInfo
列是RoomType,RoomNo,FloorNo
表2> PaymentInfo
列是CustomerID,Rate,Discount(浮动数据类型),Amount,TotalAmount,Prepaid,Remain
上面的表是使用T-Sql查询在同一数据库中创建的.
现在的问题是Table2中的Rate列取决于Table1的RoomType(即如果RoomType说成"Double",Rate列中的值将为Rs120).如何在此处使用sql函数来解决问题.
我也知道用于计算
的sql命令应该是什么 金额=费率-(折扣*费率)
TotalAmount = Amount * NoOfDaysStaying ......这里NoOfDaysStaying在另一张表中.....请帮助我.... ..

I have created two tables
Table 1>RoomInfo
Columns are RoomType,RoomNo,FloorNo
Table 2>PaymentInfo
Columns are CustomerID,Rate,Discount(Float data type),Amount,TotalAmount,Prepaid,Remain
Above tables are created in same database with T-Sql query.
Now the problem is Rate column in Table2 is dependent on RoomType of Table1(i.e if RoomType is say ''Double'' the value in Rate column of will be Rs120).How I can use the sql function over here to get my problem solved.
I also know what should be the sql commands for calculating
Amount=Rate-(Discount*Rate)
TotalAmount=Amount*NoOfDaysStaying ...............Here NoOfDaysStaying is in another table.................Pls help me......

推荐答案

我认为您正在寻找 ^ ]在SQL中.

你会做这样的事情:
Rate = CASE WHEN RoomType="Double" THEN 120 ELSE 60 END

CASE WHEN RoomType="Double" THEN 120 ELSE 60 END as Rate
取决于您运行的是哪种SQL语句或如何构建表.
I think you are looking for the case statement[^] in SQL.

You''d do something like this:
Rate = CASE WHEN RoomType="Double" THEN 120 ELSE 60 END
or
CASE WHEN RoomType="Double" THEN 120 ELSE 60 END as Rate
Depending upon what kind of an SQL statement you are running or how you are building your table.


这篇关于SQL函数AT列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆