SQL查询结果不符合预期 [英] SQL query result not as expected

查看:86
本文介绍了SQL查询结果不符合预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有12条记录。我想在序列中显示金额,日期和分期付款12次,但贷款ID只连续一次。帮助我。



提前预付



选择c.Loan_id,i.Installment_no, i.Date,i.Amount from Customer c,Installments i,Loan l where l.Loan_id = c.Loan_id and c.Loan_id = i.Loan_id; 

解决方案

zeshanazam,



理想情况下,您只需限制代码中的输出。但是如果你必须只在一行输出它,请尝试以下方法。我假设您正在使用SQL Server。不同的数据库可能会改变语法。



 选择  CASE  i.Installment_no 
WHEN 1 那么 c.Loan_id
ELSE null
END AS Loan_ID
,i.Installment_no
,i。 日期
,i.Amount
来自客户c
,分期付款i
,贷款l
其中 l.Loan_id = c.Loan_id
c.Loan_id = i.Loan_id;





Hogan


i have 12 record. i want to show Amount,date and installment no 12 times in a sequence but loan id only one time in a row. help me with this.

thanX in advance

Select c.Loan_id,i.Installment_no,i.Date,i.Amount from Customer c,Installments i,Loan l where l.Loan_id=c.Loan_id and c.Loan_id=i.Loan_id;

解决方案

zeshanazam,

Ideally, you would just limit the output in the code. But if you have to only have it output on one row, try the following. I''m assuming you''re using SQL Server. Different database may change the syntax.

Select 	CASE i.Installment_no
	  WHEN 1 THEN c.Loan_id
	  ELSE null
	END AS Loan_ID
	,i.Installment_no
	,i.Date
	,i.Amount 
from Customer c
	,Installments i
	,Loan l 
where l.Loan_id = c.Loan_id 
and c.Loan_id = i.Loan_id;



Hogan


这篇关于SQL查询结果不符合预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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