0
select extract (year from CRIME_DATE) year,
SUM (CRIME_NO)
from crime
group by select extract (year from CRIME_DATE) CRIME_DATE
order by select extract (year from CRIME_DATE) year

I am trying to use the above query to produce a chart in application builder in apex but to make sure it works i am testing it on SQL commands but i keep getting the missing expression error can anyone help?

9
  • you should remove CRIME_DATE and year from the end of the group by and order by lines Commented Apr 24, 2014 at 16:37
  • no i still get the same error Commented Apr 24, 2014 at 16:39
  • I still get the same error Commented Apr 24, 2014 at 16:40
  • you have the SELECT keyword in the GROUP BY and ORDER BY. Please remove them as well as the column aliases. Commented Apr 24, 2014 at 16:40
  • also remove the select from before the extract Commented Apr 24, 2014 at 16:40

2 Answers 2

2
select extract (year from CRIME_DATE) year,
SUM (CRIME_NO)
from crime
group by extract (year from CRIME_DATE)
order by extract (year from CRIME_DATE)

This should fix the problems. You had additional column names after the extract in group by/order by (if you want multiple columns to identify these by you should use commas) and they also had selects in the line which should have been there.

For the chart error....maybe try this (little rusty on Oracle so not sure this will work):

select extract (year from CRIME_DATE) year,
SUM (CRIME_NO)
from crime
group by extract (year from CRIME_DATE)
order by year
Sign up to request clarification or add additional context in comments.

6 Comments

This works in SQL commands but when i apply it to the chart i get this error: 1 error has occurred Invalid chart query: select extract (year from CRIME_DATE), SUM (CRIME_NO) from crime group by extract (year from CRIME_DATE) order by extract (year from CRIME_DATE) Use the following syntax: SELECT LINK, LABEL, VALUE FROM ... Or use the following syntax for a query returning multiple series: SELECT LINK, LABEL, VALUE1 [, VALUE2 [, VALUE3...]] FROM ... LINK URL LABEL Text that displays along a chart axis. VALUE1, VALUE2, VALUE3...
@user3499533 try the updated answer...not sure if this is "legal" or not in Oracle
@MarshallTigerus - no, that isn't legal; you can only refer to a column alias in an order by, not in the group by.
@AlexPoole so the modified version I just updated would be legal then
@user3499533 sorry, I'm out of ideas for the chart error
|
0

Addressing just the chart error - Marshall Tigerus has addressed your initial error - the error from the chart builder is quite clear, and there are samples. You need to use specific column aliases; and you also need to COUNT rather than SUM, I think:

select NULL link,
  extract (year from CRIME_DATE) label,
  COUNT (CRIME_NO) value
from crime
group by extract (year from CRIME_DATE)
order by extract (year from CRIME_DATE);

2 Comments

The query works but the results seem to be inaccurate for example i have 3 crimes which have a crime_date with a year of 2013 but for some reason its shows as a staggering 21 crime when i only have 10 crimes in the table, any ideas why?
@user3499533 - you're doing SUM; did you mean COUNT, perhaps? Summing the crime numbers would seem quite an odd thing to do - it doesn't tell you anything really. And you could get big numbers, quite quickly...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.