aggregate-functions

Parse Date from MM/DD/YYYY to a format MYSQL can work with

早过忘川 提交于 2019-12-31 07:01:16
问题 Currently working with a MLS data dump in which all their dates are formatted in MM/DD/YYYY , Trying to get the min/max age MIN( DateDiff( NOW(), idx_common.list_date ))) AS listage_min, MAX( DateDiff( NOW(), idx_common.list_date ))) AS listage_max Obviously this does not work because idx_common.list_date is in said format. Any ideas? 回答1: Use str_to_date to convert idx_common.list_date . MIN( DateDiff( NOW(), str_to_date(idx_common.list_date,'%m/%d/%Y') ))) AS listage_min, MAX( DateDiff( NOW

Parse Date from MM/DD/YYYY to a format MYSQL can work with

徘徊边缘 提交于 2019-12-31 07:01:04
问题 Currently working with a MLS data dump in which all their dates are formatted in MM/DD/YYYY , Trying to get the min/max age MIN( DateDiff( NOW(), idx_common.list_date ))) AS listage_min, MAX( DateDiff( NOW(), idx_common.list_date ))) AS listage_max Obviously this does not work because idx_common.list_date is in said format. Any ideas? 回答1: Use str_to_date to convert idx_common.list_date . MIN( DateDiff( NOW(), str_to_date(idx_common.list_date,'%m/%d/%Y') ))) AS listage_min, MAX( DateDiff( NOW

counting mysql values

╄→尐↘猪︶ㄣ 提交于 2019-12-31 06:20:40
问题 I have a table with two fields, TAG_ID and TAG_DESC my primary is tag_id. I'm looking for a query that will display each TAG_DESC and the amount of times it occurs next to it. Thanks, 回答1: SELECT TAG_DESC as 'Description', COUNT(TAG_DESC) as 'Occurances' FROM table_name GROUP BY TAG_DESC 回答2: select TAG_DESC, count(*) from MyTable group by TAG_DESC 来源: https://stackoverflow.com/questions/3808062/counting-mysql-values

Get created as well as deleted entries of last week

风格不统一 提交于 2019-12-31 05:24:07
问题 With this query I can get all entries created during the last week: SELECT day, COALESCE(ct, 0) AS ct FROM (SELECT now::date - d AS day FROM generate_series (0, 6) d) d -- 6, not 7 LEFT JOIN ( SELECT created_at::date AS day, count(*) AS ct FROM entries WHERE created_at >= date_trunc('day', now()) - interval '6d' GROUP BY 1 ) e USING (day); It returns a result like this one: count | date 2 | 15.01.2014 0 | 14.01.2014 1 | 13.01.2014 0 | 12.01.2014 0 | 11.01.2014 0 | 10.01.2014 9 | 09.01.2014

Pass extra parameter to PostgreSQL aggregate final function

北慕城南 提交于 2019-12-31 02:23:11
问题 Is the only way to pass an extra parameter to the final function of a PostgreSQL aggregate to create a special TYPE for the state value? e.g.: CREATE TYPE geomvaltext AS ( geom public.geometry, val double precision, txt text ); And then to use this type as the state variable so that the third parameter (text) finally reaches the final function? Why aggregates can't pass extra parameters to the final function themselves? Any implementation reason? So we could easily construct, for example,

How to translate the PostgreSQL array_agg function to SQLite?

人走茶凉 提交于 2019-12-30 08:29:28
问题 This query works in PostgreSQL: Select ot.MCode,array_to_string(array_agg(tk1.TName || ',' || ot.TTime), ' - ') as oujyu_name_list From TR_A ot inner join MS_B tk1 on ot.Code = tk1.Code Where ot.Code in (Select Code From TR_C ) Group byot.MCode but it does not work in SQLite, because SQLite does not have the array_agg() function. How can this query be converted to SQLite? 回答1: For this query, you can use group_concat, which directly returns a string: SELECT ..., group_concat(tk1.TName || ','

How sum with case conditional statement works in sql

五迷三道 提交于 2019-12-30 07:31:47
问题 The other day, I gave an answer to this question but then other user solved that problem with sum + case conditional statement to add one edge condition in result. So, the question came to my mind, how statement sum(case when jobname = 'Analyst' then 1 else 0 end) in the below query works select d.* from (select deptno, sum(case when jobname = 'Analyst' then 1 else 0 end) as numAnalysts from employees group by deptno order by numAnalysts asc ) d where rownum = 1;` and return the number of

Querying count on daily basis with date constraints over multiple weeks

こ雲淡風輕ζ 提交于 2019-12-30 05:14:28
问题 I'm trying to find the # active users over time on a daily basis. A user is active when he has made more than 10 requests per week for 4 consecutive weeks . ie. On Oct 31, 2014, a user is active if he has made more than 10 requests in total per week between: Oct 24-Oct 30, 2014 AND Oct 17-Oct 23, 2014 AND Oct 10-Oct 16, 2014 AND Oct 3-Oct 9, 2014 I have a table of requests : CREATE TABLE requests ( id text PRIMARY KEY, -- id of the request amount bigint, -- sum of requests made by accounts_id

Does GQL support commonly available SQL Style aggregation?

南笙酒味 提交于 2019-12-30 04:59:04
问题 What I'm looking for a simple Aggregate Functions that are widely available in versions of SQL. Simple things like Select Count(*) from table1 to the more complex. If these are available, is there some documentation you could point me to? Thanks - Giggy 回答1: The SQL aggregate functions are not available. What you want to do is follow patterns like the sharded counters example: http://code.google.com/appengine/articles/sharding_counters.html which explain that instead of aggregating the values

How to load extensions into SQLite?

ぐ巨炮叔叔 提交于 2019-12-30 04:02:29
问题 I need a standard deviation function in SQLite. I have found one here: http://www.sqlite.org/contrib?orderby=date but its part of an extension file to SQLite. I've never installed one of these before and I don't know how to. I found this existing function, load_extension , at http://www.sqlite.org/lang_corefunc.html, but I don't understand what the parameters X and Y are. Basically, I need someone to give me a step by step guide on how to install the aggregate extension file. Can anyone do