How to group by year
Hi,
I have the following simple query:
SELECT pubdate, title
FROM table
ORDER BY date DESC
Which returns hundreds of records. Instead of outputing every
single date within a year for pubdate, I would like to group the
output based on the year. So the display would like something like:
2008
2007
2006
1970 etc.
How can I output this?
jenn wrote:
> But this displays all the dates within a year. I just
want to display the #DatePart("yyyy", date# to get
> 2008, 2007 etc. and not 5/21/08, 5/21/08....1/1/1979.
Well then that is what would need to be in your query. Ok you
could do
it with code in the CFML, but that would be much more effort.
SELECT pubdate, title, year(pubDate) AS year
FROM table
ORDER BY year(pubdate) DESC, pubdate DESC
<!--- this is a pseudo code example. The exact SQL date
function will
very from one database management system to another. --->
<cfoutput query="simpleQry" group="year">
#year#
<cfoutput>
#pubDate#: #title#<br/>
<cfoutput>
<hr/>
</cfoutput>
Similar Messages
-
How to group each 3 months of a year and dynamic a new column?
I have a sql which can display the belows records.
YEARS MONTHS SUMMONTH SUMYEAR
2009 Apr 130288 1720164
2009 Aug 138776 1720164
2009 Dec 140294 1720164
2009 Feb 136422 1720164
2009 Jan 148253 1720164
2009 Jul 149842 1720164
2009 Jun 122805 1720164
2009 Mar 145872 1720164
2009 May 151193 1720164
2009 Nov 133487 1720164
2009 Oct 169443 1720164
2009 Sep 153489 1720164
2010 Apr 142255 1719457
2010 Aug 135894 1719457
2010 Dec 171203 1719457
2010 Feb 137011 1719457
2010 Jan 145493 1719457
2010 Jul 137474 1719457
2010 Jun 154411 1719457
2010 Mar 133062 1719457
2010 May 146887 1719457
2010 Nov 139869 1719457
2010 Oct 127191 1719457
2010 Sep 148707 1719457
24 rows selected The SQL that I am using:
select years, months, summonth, sumyear
from(
select years, months, SUM (sumHour) OVER (PARTITION BY years,months) sumMonth, SUM (sumHour) OVER (PARTITION BY years) sumyear
from (SELECT x.years, x.months, x.days, x.hours, x.mins, sum(x.value) as sumHour
FROM xmltest,
XMLTABLE ('$d/cdata/name' passing xmldoc as "d"
COLUMNS
years integer path 'year',
months varchar(3) path 'month',
days varchar(2) path 'day',
hours varchar(2) path 'hour',
mins varchar(2) path 'minute',
value float path 'value'
) as X
group by x.years, x.months, x.days, x.hours, x.mins
order by x.years, x.months, x.days
group by years,months,summonth,sumyear
order by yearsand now the problems is...how can I group the sum of 3months of record as a quarter of year in a dynamic column?
The display should be likie this:
YEARS MONTHS SUMMONTH SUMQUARTER SUMYEAR
2009 Feb 136422 430547 1720164
2009 Jan 148253 430547 1720164
2009 Mar 145872 430547 1720164
2009 Apr 130288 404286 1720164
2009 Jun 122805 404286 1720164
2009 May 151193 404286 1720164
2009 Aug 138776 442107 1720164
2009 Jul 149842 442107 1720164
2009 Sep 153489 442107 1720164
2009 Dec 140294 443224 1720164
2009 Nov 133487 443224 1720164
2009 Oct 169443 443224 1720164
2010 Feb 137011 415566 1719457
2010 Jan 145493 415566 1719457
2010 Mar 133062 415566 1719457
2010 Apr 142255 443553 1719457
2010 Jun 154411 443553 1719457
2010 May 146887 443553 1719457
2010 Aug 135894 422075 1719457
2010 Jul 137474 422075 1719457
2010 Sep 148707 422075 1719457
2010 Dec 171203 438263 1719457
2010 Nov 139869 438263 1719457
2010 Oct 127191 438263 1719457
24 rows selected Thanks everyone helps me.!!may be using an outer select :
SQL> with sample_tab as
2 (
3 select 2009 year, 'Aug' month, 138776 summonth , 1720164 sumyear from dual union all
4 select 2009,'Apr',130288, 1720164 from dual union all
5 select 2009,'Dec', 140294 , 1720164 from dual union all
6 select 2009,'Feb', 136422 , 1720164 from dual union all
7 select 2009,'Jan', 148253 , 1720164 from dual union all
8 select 2009,'Jul', 149842 , 1720164 from dual union all
9 select 2009,'Jun', 122805 , 1720164 from dual union all
10 select 2009,'Mar', 145872 , 1720164 from dual union all
11 select 2009,'May', 151193 , 1720164 from dual union all
12 select 2009,'Nov', 133487 , 1720164 from dual union all
13 select 2009,'Oct', 169443 , 1720164 from dual union all
14 select 2009,'Sep', 153489 , 1720164 from dual union all
15 select 2010,'Apr', 142255 , 1719457 from dual union all
16 select 2010,'Aug', 135894 , 1719457 from dual union all
17 select 2010,'Dec', 171203 , 1719457 from dual union all
18 select 2010,'Feb', 137011 , 1719457 from dual union all
19 select 2010,'Jan', 145493 , 1719457 from dual union all
20 select 2010,'Jul', 137474 , 1719457 from dual union all
21 select 2010,'Jun', 154411 , 1719457 from dual union all
22 select 2010,'Mar', 133062 , 1719457 from dual union all
23 select 2010,'May', 146887 , 1719457 from dual union all
24 select 2010,'Nov', 139869 , 1719457 from dual union all
25 select 2010,'Oct', 127191 , 1719457 from dual union all
26 select 2010,'Sep', 148707 , 1719457 from dual
27 )
28 select year,
29 month,
30 summonth,
31 sum(summonth) over(partition by year || to_char(ym, 'Q') order by year || to_char(ym, 'Q')) sumquarter,
32 sumyear
33 from (
34 select year,
35 month,
36 summonth,
37 sumyear,
38 to_date(year || month, 'YYYYMon') ym
39 from sample_tab)
40 order by ym
41 ;
YEAR MONTH SUMMONTH SUMQUARTER SUMYEAR
2009 Jan 148253 430547 1720164
2009 Feb 136422 430547 1720164
2009 Mar 145872 430547 1720164
2009 Apr 130288 404286 1720164
2009 May 151193 404286 1720164
2009 Jun 122805 404286 1720164
2009 Jul 149842 442107 1720164
2009 Aug 138776 442107 1720164
2009 Sep 153489 442107 1720164
2009 Oct 169443 443224 1720164
2009 Nov 133487 443224 1720164
2009 Dec 140294 443224 1720164
2010 Jan 145493 415566 1719457
2010 Feb 137011 415566 1719457
2010 Mar 133062 415566 1719457
2010 Apr 142255 443553 1719457
2010 May 146887 443553 1719457
2010 Jun 154411 443553 1719457
2010 Jul 137474 422075 1719457
2010 Aug 135894 422075 1719457
YEAR MONTH SUMMONTH SUMQUARTER SUMYEAR
2010 Sep 148707 422075 1719457
2010 Oct 127191 438263 1719457
2010 Nov 139869 438263 1719457
2010 Dec 171203 438263 1719457
24 rows selected
SQL> -
How to group my videos by year/hard disk
The new iMovie with the Mavericks seems to sort all the movies based on date when they were imported rather than the date videos were created.
iMovies 11 nicely grouped them by year and hard disk if i wanted but dont see any option on the imovies that came with mavericks
Is there a way to change the view as it was in imovies 11?I need this back too. In the previous version of iMovie, I really liked being able to see all of my raw video that I have imported over the years grouped by year on the left side of the screen. Makes it so much easier when it's time to make a video montage or other video containing clips from multiple years. If someone knows how to re-enable this in the new version of iMovie, please let me know. If it's been removed, I need to know that as well as that is a deal-breaker for me, and I will just stick with the current version.
Thanks. -
Hi,
I use Aperture 3.1.1 and have added a project which contains pictures from 2010 and 2011. I have the option "Group by year" enabled and display "newest first". Usually Aperture sorts every project which contains two years above the oldest year. So it should be sorted like:
2011
2010-2011
2010
2009
2008
2007-2008
2007
However Aperture sorts as follows:
2011
2010
2010-2011
2009
2008
2007-2008
2007
Did I miss a setting here?
Any ideas on how to fix it so I would get displayed as the first example?
Thanks a lot,
JoernJoern18 wrote:
Any other ideas?
An easy one to try:
Create a new, empty Project. Give it a very simple name. Select all the images in the problem Project and move them to the new Project. Delete the old Project. Go to Project view and try the "group by year", "sort by date" again.
If it fails, try it again with a subset of the images to see if it is an image that is causing the problem.
You could also rebuild your Library. This is the last step in the progression "Repair permissions", "Repair Library", "Rebuild Library". For a large Library this will take hours. -
How to add FISCAL YEAR, Period and Day to cube.
hi,
I am using SD EXTRACTORS (2LIS_11_VAITM, 2LIS_11_VAKON, 2LIS_12_VCITM and 2LIS_13_VDITM) and directly updating each corresponding ODS and cube.
All the extractors only have FISCAL VARIANT has the time characteristic. So, all my ODS contains only one time char - fiscal variant and other dates (liek document created date etc. (not a time char)).
Now, I want to use fiscal period, fiscal year and fiscal day in my cube. I have added these time char in my cube.
My question:
1. how to get FISCAL YEAR, FISCAL PERIOD and FISCAL DAY get updated. Do I need to map to document created date in update rules or Do I need to use some functional module.
Pls note I am bringing only FISCAL VARIANT from R/3 into ODS and then to CUBE.
PLS REPLY.thanks sundar..i got your point..but I have one question
All the cubes (sales, sales condition and billing) have the sales order number (VBUK-VBELN) and item number (POSNR-VBUK). But info objects used for these fields in sales cube and sales condition cube are same but for billing it is not same.
Can I combine all cubes (sales order, sales condition, billing) in muliti provider.
1. Sales order cube (from VAITM)
Sales order number (VBUK-VBELN) -- (0DOC_NUMBER)
Sales Item (VBUK-POSNR) -- (0S_ORD_ITEM)
Date : Document created date (VBAK-AUDAT) -- 0DOC_DATE
2. Sales Condition cube (from VAKON)
Sales order number (VBUK-VBELN) -- (0DOC_NUMBER)
Sales Item (VBUK-POSNR) -- (0S_ORD_ITEM)
Date: Document created date (VBAK-AUDAT) -- 0DOC_DATE
Key field: Netprice (VBAP-NETWR) -- 0NET_VALUE
3. Delivery Cube (from VCITM)
Sales order number (VBUK-VBELN) -- (0DELIV_NUMB)
Item (VBUK-POSNR) -- (0DELIV_ITEM)
Date: Delivery Date :LIKP-WADAT_IST -- 0ACT_GI_DTE
4. Billing Cube (from VDITM)
Sales order number (VBUK-VBELN) -- (0BILL_NUM)
Sales Item (VBUK-POSNR) -- (0BILL_ITEM)
Date: Billing Date: (VBRK-FKDAT) -- (0BILL_DATE)
Key field: Net price (VBRP-NETWR) -- 0NETVAL_INV
I want to combine above cubes. If I combine, Will I get correct data??????
Points will be assigned to every useful answer -
How to Change Fiscal year in Consolidation
HI all,
How to change Fiscal year in consolidation...iam posting the documents.... not showing any valuues in consolidation report only shwoing documents nos only ... bcoz its whoing 2007 fiscal year....
regards
JKhi
go to OKKP
here select the controlling area then click on Activate components/control indicators
here u have to do following entries
Cost Centers act
Order Management act
Commit. Management act
ProfitAnalysis not act
Acty-Based Costing not act
plz consult a FI guy for this
regards
KI -
How to change budget year in PO
Hi
How to change budget year in PO
Thanks
AjitDepends on the pattern of the dates. The last procedure will work for any pattern, or no pattern at all.
For examples.the dates are assumed to be in column A, starting at A2
Sequential dates?
Enter first updated date in the first cell.
Enter =A2+1 in cell A3. Copy the cell.
Select A3 to the end of the list. Paste.
With the cells still selected, Copy, then go Edit > Paste Values.
Evenly spaced dates?
Same procedure as above, but replace +1 in the formula with + and the number of days between dates in the list.
Randomly spaced dates?
Select cell B2. Press option-left arrow to insert a (temporary) column to the left of column B.
Click on the empty cell B2 in the new column. Enter the formula below:
=DATE(YEAR(A)+1,MONTH(A),DAY(A))
Copy the cell, then select B2 - Bn where n is the last ow containing a date to be converted. Paste,
With the cells still selected, Copy.
Click on A2, then go Edit > Paste values.
Click on the column B reference tab to select all of column B.
Hover the mouse over the right end of the reference tab, and click the black triangle when it appears.
Choose Delete Column from the menu that appears.
Regards,
Barry -
How to open Fiscal year in Asset Accounting ( AJRW )
HI
how to open fiscal year in Asset Accounting (AJRW), if i open it how to check.
Thank you.Hi Anil,
To open fiscal year use AJRW. use T-Code OAAQ to check the same
prasanna -
How to find leap year in sql query
How to find leap year in sql query
Select
CASE
WHEN result = 0 THEN 'Leap_Year'
WHEN result <> 0 THEN 'Not_A_Leap_Year'
END
From (Select mod((EXTRACT(YEAR FROM DATE '2013-08-24')), 4) result FROM DUAL); -
How to change the year in a range of column dates to the new year?
How to change the year in a range of column dates to the new year?
Depends on the pattern of the dates. The last procedure will work for any pattern, or no pattern at all.
For examples.the dates are assumed to be in column A, starting at A2
Sequential dates?
Enter first updated date in the first cell.
Enter =A2+1 in cell A3. Copy the cell.
Select A3 to the end of the list. Paste.
With the cells still selected, Copy, then go Edit > Paste Values.
Evenly spaced dates?
Same procedure as above, but replace +1 in the formula with + and the number of days between dates in the list.
Randomly spaced dates?
Select cell B2. Press option-left arrow to insert a (temporary) column to the left of column B.
Click on the empty cell B2 in the new column. Enter the formula below:
=DATE(YEAR(A)+1,MONTH(A),DAY(A))
Copy the cell, then select B2 - Bn where n is the last ow containing a date to be converted. Paste,
With the cells still selected, Copy.
Click on A2, then go Edit > Paste values.
Click on the column B reference tab to select all of column B.
Hover the mouse over the right end of the reference tab, and click the black triangle when it appears.
Choose Delete Column from the menu that appears.
Regards,
Barry -
How to show current year and last year sales in a WEBI Report
Hi Guys
How can show current YEar Sales in one column and Last YEar Sales in the other column based on a user prompt for the Current YEar Column.
For Example is user enter 2010 for Year how can i show a Column for Sales-2010 and Sales 2009.
ThanksIf you can modify your Universe add an object named New Object Last Year whose SQL is:( yourTableName.Year + 1)
Then in WebI create two distinct queries in your query Pane. In the first one you could do this:
Query 1:
objects: Year, Sales ... etc.
filters: Year Equal to '1. Prompt Year'
Query 2:
objects: Year, Sales ... etc.
filters: New Object Last Year Equal to '1.Prompt Year'
Then in your report you can drag each object on their respective columns.
If you don't want to use two distinct queries, use one like this:
Query 1:
objects: Year, Sales ... etc.
filters: Year Equal to '1. Prompt Year'
Or
New Object Last Year Equal to '1.Prompt Year'
Edited by: PadawanGirl on Jun 23, 2011 6:28 PM -
How to Calculate Leap Year ago in OBIEE 11g
Hi Gurus,
I have one fact table and having one measure column. I have to calculate current year and Last year.
Using Time series function (Todate,Ago) have calculated current year as well last year also.
The problem is Current year is showing correct value only but Last year was showing wrong data.
We found the problem is Leap year, last year FEB month is having 29 dates. Due to this we are getting wrong date.
Kindly suggest me how to achieve this requirement.
ThanksHi Gurus,
How to resolve Leap Year calculation in OBIEE 11g.
The problems is Year Ago column.
Please suggest me how to resolve this.
Thanks -
How to set current year,month as default value in combo box
hi, im newbie of xcelsius user
i realize that hv a issue that display combo box base on year & month
let said
<b><u>step 1</u></b>
I create excel data like this
<b><u>year___ </u> </b> | <u><b>month_ </b></u> | <u><b>Product</b></u> | <u><b>revenue</b></u>
02-04-09 | 02-04-09 | a | $4,154
03-04-09 | 03-04-09 | b | $6,813
04-05-09 | 04-05-09 | a | $9,875
05-06-09 | 05-06-09 | b | $6,813
06-04-10 | 06-04-10 | a | $6,813
07-04-10 | 07-04-10 | b | $9,875
08-06-10 | 08-06-10 | a | $9,875
22-06-10 | 22-06-10 | b | $6,813
<u><b>Step2</b></u>
Then i go format cell to format/custom date to year & month
Eg1: Year u2013> 02-04-09 convert to u2018YYYYu2019 (2009)
Eg2: Month u2013> 02-04-09 convert to u2018mmmmu2019 (April)
So output like this
<u><b>year</b></u> | <u><b>month</b></u> | <u><b>Product</b></u> | <u><b>revenue </b></u>
2009 | April | a | $4,154
2009 | April | b | $6,813
2009 | May | a | $9,875
2009 | June | b | $6,813
2010 | April | a | $6,813
2010 | April | b | $9,875
2010 | June | a | $9,875
2010 | June | b | $6,813
But the problem is when i insert to combo box,use u201Cfilter Row u201D, i excpectation will display only 2009,2010
But Actual display the Year in combo box is duplicated :'(
so any solution ? and then only how to set current year & month as default value :'(
thanks,
regards
s1
Edited by: Leong Pui Kee on Feb 25, 2011 5:25 AM
Edited by: Leong Pui Kee on Feb 25, 2011 5:36 AMhi,
your created data
step 1
I create excel data like this
year___ | month_ | Product | revenue
02-04-09 | 02-04-09 | a | $4,154
03-04-09 | 03-04-09 | b | $6,813
04-05-09 | 04-05-09 | a | $9,875
05-06-09 | 05-06-09 | b | $6,813
06-04-10 | 06-04-10 | a | $6,813
07-04-10 | 07-04-10 | b | $9,875
08-06-10 | 08-06-10 | a | $9,875
22-06-10 | 22-06-10 | b | $6,813
In this, year and month both are same data, make the diffent data like year 2009, 2010 And month Jan, Feb, March, ...Etc
and also one more check you formulas on month and year, select correct source data, destination data for compoonent..
OR
from above, to create a date column and convert date-->year, date--> month and Explore it.
All the best,
Praveen -
How to group photos in folders, in the main photos app in my iphone4 ?
How to group photos in folders, in the main photos app in my iphone4 ?
You can update your iPhone to iOS 5, in iOS 5, it will allow you to create albums in your photo app and it also allows you to move the photos from album to another album
-
How to group a report by formula field.
Hi,
I need to create a report based on the following report:
http://s464.photobucket.com/albums/rr8/einas121809/
This new report should be grouped by days and status. Then, each group should display the details of each record such as Report No, Open Date , Due Date and Summary.
It is not a problem to display the report details, but I need to know how to group them since it involve calculation.
Thank you in advance,
Regards,
einas.Hello,
Right what you want to do is to get a crosstab which can be found in your toolbar or under Insert menu Insert --->Crosstab.
You might need to use a working day formula something like this
WhileReadingRecords;
Local DateVar Start := {StartDate}; // place your Starting Date here
Local DateVar End := {EndDate}; // place your Ending Date here
Local NumberVar Weeks;
Local NumberVar Days;
Local Numbervar Hol;
DateVar Array Holidays;
Weeks:= (Truncate (End - dayofWeek(End) + 1
- (Start - dayofWeek(Start) + 1)) /7 ) * 5;
Days := DayOfWeek(End) - DayOfWeek(Start) + 1 +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);
Local NumberVar i;
For i := 1 to Count (Holidays)
do (if DayOfWeek ( Holidays<i> ) in 2 to 6 and
Holidays<i> in start to end then Hol:=Hol+1 );
Weeks + Days - Hol
If you need to calculate bank holidays then you have to create an array like this
//Holiday Listing formula to go into the report header of the report.
BeforeReadingRecords;
DateVar Array Holidays := [
Date (2003,12,25),
Date (2003,12,31)
0
The workingdays formula needs to go into the Row and then distinct Count your orders. That should give you how many orders took x amount of days.
Then you need to further develop your formula so that it shows <20 days, more than 20 days etc.
Create something like this first and then ask further questions if you are stuck.
Hope this helps
Regards
jehanzeb
Maybe you are looking for
-
Keyboard lights settings on Qosmio X70
Hi guys and girls Just got a new TOSHIBA Qosmio X70. Is it possible to make the keyboard back lights stay on longer ?? Many thanks Lee
-
On Safari browser I have no visible toolbar, how do I get it back?
On opening the Safari browser I do not have a visible toolbar, just three icons, read, iCloud, link and the split address bar and search bar. How do I get.a full toolbar visible in the browser display?
-
I AM ANALYZING THIS PROGRAM CAN U TELL ME FROM WHICH POINT I HAVE TO START
TABLES: VBAP, "Sales Document: Item Data VBUP, "Sales Document: Item Status VBAK, "Sales Document: Header Data LIPS, "SD docum
-
Address Book: can't "re-open" window once I closed it (Command-W)
I closed the Address Book window (Command-W) and now want to "re-open" it. So I press Command-Tab to get to Address Book and I can't "re-open" Address Book so I can see it again!
-
hey there all, here's a real perplexing issue... i tried to help out a young friend, an aspiring filmmaker & so i installed my copy of iLife 08 onto her 17" iMac C2D w/ OS 10.4.10 & 2 GB of RAM(only have so much $$-couldn't buy her her own copy & my