Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 查找EC1区域中为每个帐户创建的第三大报价_Sql Server_Tsql_Join_Sql Order By_Sql Limit - Fatal编程技术网

Sql server 查找EC1区域中为每个帐户创建的第三大报价

Sql server 查找EC1区域中为每个帐户创建的第三大报价,sql-server,tsql,join,sql-order-by,sql-limit,Sql Server,Tsql,Join,Sql Order By,Sql Limit,有人能帮我吗?我是SQL新手,正在尝试解决以下问题,请参见图表了解表结构 问题=为EC1区域中每个帐户创建的f第三大报价选择帐户名、联系人姓氏、案例编号、报价编号、报价日期和报价值 到目前为止,我得到了 Select a.accountname, cc.lastname, c.casenumber, q.quotenumber, q.quotedate, q.quotevalue from TBL_Quote q Left join TBL_case

有人能帮我吗?我是SQL新手,正在尝试解决以下问题,请参见图表了解表结构

问题=为EC1区域中每个帐户创建的f第三大报价选择帐户名、联系人姓氏、案例编号、报价编号、报价日期和报价值

到目前为止,我得到了

Select 
    a.accountname, cc.lastname, c.casenumber, 
    q.quotenumber, q.quotedate, q.quotevalue 
from 
    TBL_Quote q 
Left join 
    TBL_case c On q.caseid = c.caseid 
Left join 
    tbl_contact cc On c.contactID = cc. contactID 
Left join    
    tbl_account a On a.accountid = cc.accountid 
Where 
    left(a.postcode, 3) like 'EC1' 
第三项:

SELECT TOP 1 value 
FROM 
    (SELECT DISTINCT TOP 3 value 
     FROM tbl_quote 
     ORDER BY value DESC) a 
ORDER BY value 

我似乎无法将前三名和问题结合起来,是否最好按比例多分配

我建议使用连接和行限制子句:

select ac.accountName, co.lastName, ca.caseNumber, qu.quoteNumber
from tbl_account       ac
inner join tbl_contact co on co.accountId = ac.accountId
inner join tbl_case    ca on ca.contactId = co.contactId
inner join tbl_quote   qu on qu.caseId    = ca.quoteId
where ac.postcode like 'EC1%'
order by len(qu.value) desc
offset 2 rows fetch next 1 row only

我建议使用连接和行限制条款:

select ac.accountName, co.lastName, ca.caseNumber, qu.quoteNumber
from tbl_account       ac
inner join tbl_contact co on co.accountId = ac.accountId
inner join tbl_case    ca on ca.contactId = co.contactId
inner join tbl_quote   qu on qu.caseId    = ca.quoteId
where ac.postcode like 'EC1%'
order by len(qu.value) desc
offset 2 rows fetch next 1 row only

这看起来像是一个家庭作业问题。你试过什么,为什么不奏效?或者你做了什么研究,你不明白吗>?嗨,拉奴,没错,这是一个我发现我正在尽可能多地练习的在线问题。选择a.accountname,cc.lastname,c.casenumber,q.quotenumber,q.quotedate,q、 quotevalue from TBL Quote q Left join TBL Quote q上的案例c.caseid=c.caseid Left join TBL\U c.contactID=cc上的联系人cc。contactID Left join tbl_帐户a在a.accountid=cc.accountid上,其中lefta.postcode,3像“EC1”一样,从中选择前1个值从tbl中选择不同的前3个值按值顺序描述按值顺序我已经了解了上述内容,似乎无法将前3个值与query@Huss1:请直接在其中添加查询。这看起来像是一个家庭作业问题。你试过什么,为什么不奏效?或者你做了什么研究,你不明白吗>?嗨,拉奴,没错,这是一个我发现我正在尽可能多地练习的在线问题。选择a.accountname,cc.lastname,c.casenumber,q.quotenumber,q.quotedate,q、 quotevalue from TBL Quote q Left join TBL Quote q上的案例c.caseid=c.caseid Left join TBL\U c.contactID=cc上的联系人cc。contactID Left join tbl_帐户a在a.accountid=cc.accountid上,其中lefta.postcode,3像“EC1”一样,从中选择前1个值从tbl中选择不同的前3个值按值顺序描述按值顺序我已经了解了上述内容,似乎无法将前3个值与query@Huss1:请直接在其中添加查询。