query not running on heroku console - sql

I am really stuck with query on Heroku.
I am trying to run the following query on heroku console
SELECT DATE(TimeLogin) AS d, COUNT(*) AS c FROM histories GROUP BY DATE(TimeLogin)
but I get following error,
syntax error, unexpected tCONSTANT,expecting $end
SELECT DATE(TimeLogin) AS d, COUNT(*) AS c FROM histor...
^
My heroku has postgresql
Please let me know what is the problem with this query
Regards.

i added double quotes for column names like this
SELECT DATE("TimeLogin") AS d, COUNT(*) AS c FROM histories GROUP BY DATE("TimeLogin")
this resolved my issue

Related

How to sum up values in Solr4.10.3

I installed Solr from CDH which version is 4.10.3-cdh5.13.0.
My job like one sql work like,How to realize by Solr4:
select D,E,sum(A),sum(B) from DOC where C='balabala' group by D , E;
I try this one,but only one column in group section.
&stats=on
&stats.field=A
&stats.field=B
&stats.facet=D
In Solr5,code below works,but in Solr4 failed:
facet=true&stats=true&stats.field={!tag=piv1}A&facet.pivot={!stats=piv1}D,E
Is there one approach ?
and one more question:
how to realize
select D,E,sum(A*B) from DOC where C='balabala' group by D , E;

Where clause with dates in hive

The where clause in the below hive query is not working
select
e.num as badge
from dbo.events as e
where TO_DATE(e.event_time_utc) > TO_DATE(select event_date from DL_EDGE_LRF_facilities.card_swipes_lastpulldate)
both event_time_utc and event_date fields are defined as strings and event_time_utc has timestamp values like '2017-09-18 20:10:19.000000' and event_date has only one date value like '2018-01-25'
i am getting an error like "cannot recognize input near 'select' 'event_date' 'from' in function specification " when i run the query, Please help
#user86683; hive does not recognize the syntax since it does not allow in-query in the inequality condition (>). You may try this query and let me know the result.
select e.num as badge
from dbo.events as e, DL_EDGE_LRF_facilities.card_swipes_lastpulldate c
where TO_DATE(e.event_time_utc) > TO_DATE(c.event_date)
You will get a warning but you may ignore it since the table for event_date has only one record.
Warning: Map Join MAPJOIN[10][bigTable=e] in task 'Map 1' is a cross product
Query ID = xxx_20180201102128_aaabb2235-ee69275cbec1
Total jobs = 1
Launching Job 1 out of 1
Status: Running (Executing on YARN cluster with App id application_09fdf345)
Hope this helps. Thanks.

IBM Informix-SQL syntax error, basic query from Microsoft BIDS to Cisco UCCX database

I'm running the below query against an IBM Informix database and getting an ERROR 42000: A syntax error has occurred. The FROM and WHERE clauses run fine in other queries, so I'm looking at the SELECT and GROUP BY portions. Any ideas what's wrong with the syntax?
SELECT COUNT(DISTINCT "informix".agentconnectiondetail.sessionid) AS calls_abandoned,
DAY("informix".agentconnectiondetail.startdatetime) AS Expr2
FROM "informix".agentconnectiondetail, "informix".contactqueuedetail, "informix".contactservicequeue
WHERE "informix".agentconnectiondetail.sessionid = "informix".contactqueuedetail.sessionid AND
"informix".contactqueuedetail.targetid = "informix".contactservicequeue.recordid AND "informix".contactqueuedetail.disposition = 1 AND
"informix".agentconnectiondetail.startdatetime BETWEEN '2016-10-1 00:00:00' AND CURRENT
GROUP BY DAY("informix".agentconnectiondetail.startdatetime)
The goal btw is to find the total number of unique calls (calls_abandoned) that occur on each day of the month (1-31).
Replace the
GROUP BY DAY("informix".agentconnectiondetail.startdatetime)
by
GROUP BY 2

Google BiqQuery Internal Error

Edit: Tidied up the query a bit. Checked running on one day (versus the 27 I need) and the query runs. With 27 days of data it's trying to process 5.67TB. Could this be the issue?
Latest ID of error run:
Job ID: ee-corporate:bquijob_3f47d425_1530e03af64
I keep getting this error message when trying to run a query in BigQuery, both through the UI and Bigrquery.
Query Failed
Error: An internal error occurred and the request could not be completed.
Job ID: ee-corporate:bquijob_6b9bac2e_1530dba312e
Code below:
SELECT
CASE WHEN d.category_grouped IS NULL THEN 'N/A' ELSE d.category_grouped END AS category_grouped_cleaned,
COUNT(UNIQUE(msisdn_token)) AS users,
(SUM(up_link_data_bytes) + SUM(down_link_data_bytes))/1000000 AS tot_data_mb
FROM (
SELECT
request_domain, up_link_data_bytes, down_link_data_bytes, msisdn_token, timestamp
FROM (TABLE_DATE_RANGE([helpful-skyline-97216:WEBLOG_Staging.WEBLOG_], TIMESTAMP('20160101'), TIMESTAMP('20160127')))
WHERE SUBSTR(http_status_code,1,1) IN ('1',
'2',
'3')) a
LEFT JOIN EACH web_usage_201601.domain_to_cat_lookup_27JAN_with_groups d
ON
a.request_domain = d.request_domain
WHERE
DATE(timestamp) >= '2016-01-01'
AND DATE(timestamp) <= '2016-01-27'
GROUP EACH BY
1
Is there something I'm doing wrong?
The problem seems to be coming from UNIQUE() - it returns repeated field with too many elements in it. The error could be improved, but workaround for you would be to use explicit GROUP BY and then run COUNT on top of it.
If you are okay with an approximation, you can also use
COUNT(DISTINCT msisdn_token) AS users
or a higher approximation parameter than the default 1000,
COUNT(DISTINCT msisdn_token, 5000) AS users
GROUP BY is the most general approach, but these can be faster if they do what you need.

join and group by query works in firebird 2.1 but not in 1.5

I have the following query that works fine in firebird 2.1, however I cannot get it to work on a db with the exact same structure in 1.5
select c.printchecknumber, v.voidamount
from checks c
join (select checknumber, sum(voidamount) as voidamount
from checkitem
where voidtype =1
group by checknumber) v on c.checknumber = v.checknumber
order by c.printchecknumber
Any ideas?
The error message is
Invalid token
Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, char 61
the error is at the start of the second select
I'm guessing that Firebird 1.5 doesn't support subqueries in the from clause. In any case, you can write this as a simpler query. The following should do what you want:
select c.printchecknumber, sum(voidamount) as voidamount
from checkitem ci join
checks c
on ci.checknumber = c.checknumber
where ci.voidtype =1
group by c.printchecknumber;
EDIT:
If you want to include checkid, then this might work:
select c.printchecknumber, c.checkid, sum(voidamount) as voidamount
from checkitem ci join
checks c
on ci.checknumber = c.checknumber
where ci.voidtype =1
group by c.printchecknumber, c.checkid;
I don't know why it does not work on an earlier system and I'd need to know the error message to help, but the following would work on any sql which supports the over() clause which I believe firebird does with 3.0
select c.printchecknumber,
sum(v.voidamount) over (partition by printchecknumber)
from checks c
join checkitem v on c.checknumber = v.checknumber and v.voidtype = 1