Jump to content

How did I made the longest explain plan with this SQL query?


Recommended Posts

Hello, I would like to write a simple query, where I count new registrations monthly.

The monster I created can't be made as an explain plan in normal time borders. I suspect my logic is somewhere flawed, syntax I think is good (at least i didn't get syntax error).

my query:

SELECT
  EXTRACT(MONTH FROM  DATABASE.REGHISTORY.X__INSDATE),
  --TRUNC(X__INSDATE, 'MONTH') as HONAP
  COUNT(X__INSDATE)
FROM
  DATABASE.REGHISTORY
GROUP BY EXTRACT(MONTH FROM  DATABASE.REGHISTORY.X__INSDATE);

 I supposed I should try to count something else, but it didnt finsih neither when I tried to count IDs.

I would like my table in a format simply like: month/Summed registrations that month

EDIT: I also wanted to order by maybe in ascending order, but for now I try to make it so it gives back what I want first

EDIT2:  Oracle SQL developer 4.0.0.12 (sorry, I should have started with this..)

Thank you!

PS.: I hope this is the right thread to ask something like this, general help I thought is for autoit mostly.

Edited by SorryButImaNewbie
Link to comment
Share on other sites

I use SQLite not Oracle and SQLite doesn't have the same date dissection functions, but when I try this I get the expected result:

select substr(x__insdate, -2) as Month, count() from reghistory group by month order by month;

Hence I suspect this would work as well for you:

SELECT
  EXTRACT(MONTH FROM  DATABASE.REGHISTORY.X__INSDATE) as Month,
  COUNT()
FROM
  DATABASE.REGHISTORY
GROUP BY Month order by Month;
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thank you!

This gives me back ones and twos in both column, don't know why because the logic should be fine :) I may made it with the next code

select
trunc(x__insdate 'month') as month
count(*) -- Here I actually count x__insdate, shouldnt that be quicker then count everything?
from database.table
group by month order by month

Thank you for the input :)

Edit: -- as comment line doesn't seems to work for me

Edited by SorryButImaNewbie
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...