开发者

SQL: selecting distinct substring from a field

I'm blacking out on my basic SQL and would appreciate a quick hand:

I have a SQLite table, with 2 columns: Datetime, and a string saying something like "call from 555-555-3344".

I need a simple query that will give me a count of all distinct phone numbers that called on a certain day.

If the field had contained just the number, I could have used Select Distinct on it. How do I do it if the value (phone number) is a substring in that field (though always the last 10 digits).

Assistance, as always, much appreciated.

Gu开发者_运维问答y


You can use the following (I used 12 instead of 10 in order to include the separator -):

SELECT COUNT(DISTINCT SUBSTR(phone_nbr, -12)) 
FROM table
WHERE call_dt = :call_dt;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜