Machan, mata query ekakin adala year eke adala mase ki denekge birthdays thiyanawada kiyala hoyaganna ona. Birthdays e mase nathnam 0 result eke ennna ona.
Example, 2015, jan, 20kage birthdays thiyanawa. oya wage. (year, month, count / 2015, jan, 20 OR 2015, 1, 20)
Birthdays adala mase nathnam 0 enna ona.
Example 2017, Feb, 0 kiyala enna ona. (or 2017, 2, 0)
mama group by clause ekak dala month tikata count eka ena widiyat hada gaththa. eth awula thiyenne birthdays nathi masa wala 0 enne naha.
kohomada bn meka hariyatama hada ganne...?
danata mama hdapu query eka... (MSSQL)
Result eka...
Othana result eke 2015.4 mase bithdays nathi nisa eka result eke naha.
table eke structure eka...
[id (int), name (nvarchar), birthday (date)]
SQL (MSSQL) danna kenek innawanam help ekak denna.
Thanks.
-------------------------
Sample table
--------------------------------------------------
Hari machan.
Thanks okkotama.
wade goda.
Answer 01
Answer 02
Result
Example, 2015, jan, 20kage birthdays thiyanawa. oya wage. (year, month, count / 2015, jan, 20 OR 2015, 1, 20)
Birthdays adala mase nathnam 0 enna ona.
Example 2017, Feb, 0 kiyala enna ona. (or 2017, 2, 0)
mama group by clause ekak dala month tikata count eka ena widiyat hada gaththa. eth awula thiyenne birthdays nathi masa wala 0 enne naha.
kohomada bn meka hariyatama hada ganne...?
danata mama hdapu query eka... (MSSQL)
Code:
select year(birthday) as 'Year', month(birthday) as 'Month', count(birthday) as 'Count'
from mytable
group by month(birthday), year(birthday)
order by year(birthday)
Result eka...
Code:
2015 1 33
2015 2 35
2015 3 29
2015 5 26
2015 6 45
2015 7 42
2015 8 47
2015 9 29
2015 10 34
2015 11 41
2015 12 37
2016 1 29
2016 2 32
2016 3 31
2017 1 34
2017 2 24
2017 3 30
2017 5 29
2017 6 33
2017 7 32
2017 8 39
2017 9 37
2017 10 29
2017 11 33
2017 12 4
Othana result eke 2015.4 mase bithdays nathi nisa eka result eke naha.

table eke structure eka...
[id (int), name (nvarchar), birthday (date)]
Code:
id, name, birthday
01, saman, 2015.01.02
02, nimal, 2016.02.02
03, amal, 2017.05.02
04, kamal, 2015.09.02
05, nayana, 2015.08.02
SQL (MSSQL) danna kenek innawanam help ekak denna.
Thanks.
-------------------------
Sample table
Code:
declare @mytable table(id int, stname char(10), birthday date);
insert into @mytable values (1, 'saman', '2015.01.02')
insert into @mytable values (2, 'nimal', '2016.02.02')
insert into @mytable values (3, 'amal', '2017.05.02')
insert into @mytable values (4, 'kamal', '2015.09.02')
insert into @mytable values (5, 'nayana', '2015.08.02')
select * from @mytable t1;
Code:
declare @mytable table(id int, stname char(10), birthday date);
insert into @mytable values (1, 'saman', '2015.01.02')
insert into @mytable values (2, 'nimal', '2016.02.02')
insert into @mytable values (3, 'amal', '2017.05.02')
insert into @mytable values (4, 'kamal', '2015.09.02')
insert into @mytable values (5, 'nayana', '2015.08.02')
select year(birthday) as 'Year', month(birthday) as 'Month', count(birthday) as 'Count'
from @mytable
group by month(birthday), year(birthday)
order by year(birthday)
--------------------------------------------------
Hari machan.
Thanks okkotama.
wade goda.
Answer 01
මේක try කරලා බලපන්..
select x.*, coalesce( y.count,0) from
(SELECT distinct year(logDate) year,a.*
FROM tbl_log ,
( select 1 'month'
union
select 2 'month'
union
select 3 'month'
union
select 4 'month'
union
select 5 'month'
union
select 6 'month'
union
select 7 'month'
union
select 8 'month'
union
select 9 'month'
union
select 10 'month'
union
select 11 'month'
union
select 12 'month'
) a) x
left outer join
(
SELECT year(logDate) year , month (logDate) month ,count(*) count FROM tbl_log
group by year(logDate) ,month (logDate)) y
on x.year=y.year and x.month=y.month
Answer 02
Code:
declare @mytable table(id int, stname char(10), birthday date);
insert into @mytable values (1, 'saman', '2015.01.02')
insert into @mytable values (2, 'nimal', '2016.02.02')
insert into @mytable values (3, 'amal', '2017.05.02')
insert into @mytable values (4, 'kamal', '2015.09.02')
insert into @mytable values (5, 'nayana', '2015.08.02')
select x.*, DateName( month , DateAdd( month , x.month , -1 ) ) as 'MonthName', coalesce( y.count,0) as 'Count'
from
(SELECT distinct year(birthday) year,a.*
FROM @mytable ,
( select 1 'month'
union
select 2 'month'
union
select 3 'month'
union
select 4 'month'
union
select 5 'month'
union
select 6 'month'
union
select 7 'month'
union
select 8 'month'
union
select 9 'month'
union
select 10 'month'
union
select 11 'month'
union
select 12 'month'
) a) x
left outer join
(
SELECT year(birthday) year , month (birthday) month ,count(*) count FROM @mytable
group by year(birthday) ,month (birthday)) y
on x.year=y.year and x.month=y.month
order by x.year, x.month
Result
Code:
2015 1 January 1
2015 2 February 0
2015 3 March 0
2015 4 April 0
2015 5 May 0
2015 6 June 0
2015 7 July 0
2015 8 August 1
2015 9 September 1
2015 10 October 0
2015 11 November 0
2015 12 December 0
2016 1 January 0
2016 2 February 1
2016 3 March 0
2016 4 April 0
2016 5 May 0
2016 6 June 0
2016 7 July 0
2016 8 August 0
2016 9 September 0
2016 10 October 0
2016 11 November 0
2016 12 December 0
2017 1 January 0
2017 2 February 0
2017 3 March 0
2017 4 April 0
2017 5 May 1
2017 6 June 0
2017 7 July 0
2017 8 August 0
2017 9 September 0
2017 10 October 0
2017 11 November 0
2017 12 December 0
Last edited:

