简体   繁体   English

我正在尝试使用不同的电话号码和LTV来获取州数

[英]I am trying to get count of states with distinct phone numbers and LTV

The query i wrote is: 我写的查询是:

SELECT ST,COUNT(PHONE) FROM Consumer.Axciom092013 
WHERE MR_AMT >= (HOME_MKT_VALUE_(.45)) 
and ST = 'TX' or ST = 'CA' or ST = 'AZ' or ST = 'CO' or ST = 'FL';

Simply i am trying to find the LTV (Loan-To-Value) ratio of those states, but right now I only need the count of how many records of distinct phone numbers are in each of those states. 我只是想尝试找到这些州的LTV(贷款对价值)比率,但是现在我只需要计算每个州中有多少个不同电话号码的记录。

I keep getting error about incorrect syntax in line 1. 我不断收到有关第1行中语法错误的错误。
I thought i did a step by step for it, but cannot seem to get to work! 我以为我为此做了一步,但似乎无法开始工作!

I have switched the query around and tried just running SELECT ST,COUNT(*) but then i get an error saying the function HOME_MKT_VALUE does not exist 我已切换查询,并尝试仅运行SELECT ST,COUNT(*)但随后出现错误,提示功能HOME_MKT_VALUE不存在

I suspect that you want this: 我怀疑您想要这样:

SELECT ST, COUNT(distinct PHONE)
FROM Consumer.Axciom092013 
WHERE MR_AMT >= HOME_MKT_VALUE_ * 0.45 and
      ST IN ('TX', 'CA', 'AZ', 'CO', 'FL');

SQL only does multiplication with an explicit * . SQL仅使用显式*乘法。 Your expression HOME_MKT_VALUE_(.45) is the syntax for a function call, not multiplication. 您的表达式HOME_MKT_VALUE_(.45)是函数调用的语法,而不是乘法。

I added the distinct for phone because you say you want "distinct phone numbers", implying that there could be duplicates on different rows. 我加入了distinctphone ,因为你说你要“不同的电话号码”,这意味着,有可能是在不同的行重复。

EDIT: 编辑:

By the way, your original query actually has this logic in the where clause: 顺便说一下,您的原始查询实际上在where子句中具有以下逻辑:

WHERE (MR_AMT >= HOME_MKT_VALUE_ * 0.45 and ST = 'TX')
      or ST IN ('CA', 'AZ', 'CO', 'FL');

If that is the logic you really do want, then use it instead. 如果这是您真正想要的逻辑,请改用它。

try this 尝试这个

SELECT     ST, COUNT(DISTINCT PHONE) 
FROM       Consumer.Axciom092013 
WHERE      MR_AMT >= (HOME_MKT_VALUE_(.45)) 
           and ST IN ('TX', 'CA', 'AZ', 'CO', 'FL')
GROUP BY   ST;                                    //mistaken , PHONE

EDIT: I did mistake should not be grouped by PHONE. 编辑:我没有错误,不应按PHONE分组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM