× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



You can actually have an order by in a CTE, the following SQL will give you the top 10 rows form MYFILE sorted my MYFLD:

with TEST as (
select *
from MYFILE
order by MYFIELD
fetch first 10 rows only
)

select *

from TEST

order by order of TEST


________________________________
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> on behalf of Carel <coteijgeler@xxxxxxxxx>
Sent: 17 April 2020 20:26
To: midrange-l@xxxxxxxxxxxxxxxxxx <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: sql having clause

You cannot have an ORDER BY in the CTE.


Op 17-4-2020 om 20:13 schreef Tom Hambel:
One idea would be to wrap your statement in a CTE and compare that way.

With temp(id,usage,useyear,usemonth) as
(
SELECT id, sum(metereduse), year(getdatesql(readdate)),
month(getdatesql(readdate)) FROM dailyuse
GROUP BY id, year(getdatesql(readdate)), month(getdatesql(readdate)) ORDER BY id, year(getdatesql(readdate)), month(getdatesql(readdate))
)
Select id,usage,useyear,usemonth
from temp a
Join temp b on a.id=b.id and
(a.useyear=b.useyear and b.usemonth=a.usemonth+1 and a.usemonth<12
Or a.usemonth=12 and b.usemonth=1 and b.useyear=a.useyear+1)
where b.usage>=a.usage*1.5

the join will depend on which you want to compare too.

What we did to make these scenarios much easier is create a calendar table with all attributes of a date; numeric, cymd,mdy,month,date,period, date fields etc.
Then we just join to that and do our thing.
With the date data type in the join file it makes date manipulation super easy.





CENTRAL SEMICONDUCTOR CORP. CONFIDENTIALITY NOTICE: This electronic mail transmission may be privileged, contain trade secrets, or otherwise confidential information and should be read or retained only by the intended recipient. If you have received this transmission in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fmidrange-l&amp;data=02%7C01%7C%7Ce46a453bdcc44d6f05d008d7e2fceecc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637227448267326185&amp;sdata=v2bxoZ9f48FEFXdys%2BX%2Fhmf8pf7FEJuZuBNPfTBtEQU%3D&amp;reserved=0
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fmidrange-l&amp;data=02%7C01%7C%7Ce46a453bdcc44d6f05d008d7e2fceecc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637227448267326185&amp;sdata=U5y3e9njQSogcMm5D5b2wX5xIgoYxeqqEHaFPXPVkp4%3D&amp;reserved=0.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Famazon.midrange.com%2F&amp;data=02%7C01%7C%7Ce46a453bdcc44d6f05d008d7e2fceecc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637227448267336179&amp;sdata=qFxvi6xfUbxMaDQ39swA2TRI080DCTmHSBMCPorEsoY%3D&amp;reserved=0

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.