Reputation: 164
I have a query in mysql like this
SELECT COUNT(c_Id), DATE_FORMAT(c_Date,'%Y-%m') FROM tbl_complaintsheet GROUP BY DATE_FORMAT(c_Date, '%Y%m')
Now the result is
COUNT(c_Id) DATE_FORMAT(c_Date,'%Y-%m')
----------- -----------------------------
2 2013-12
48 2014-01
85 2014-02
95 2014-03
93 2014-04
63 2014-05
94 2014-06
57 2014-07
70 2014-08
87 2014-09
83 2014-10
101 2014-11
117 2014-12
86 2015-01
126 2015-02
100 2015-03
92 2015-04
82 2015-05
1 2015-08
8 2015-09
How Can I pass parameters to this like, where c_date=2014?
Upvotes: 0
Views: 102
Reputation: 2530
Try this
SELECT COUNT(cd_Id), DATE_FORMAT(cd_Date,'%Y-%m') AS cd FROM tbl_complaintsheet WHERE YEAR(cd_date) = 2014;
Upvotes: 0
Reputation: 1958
You may try by aliasing and using like
SELECT COUNT(c_Id), DATE_FORMAT(c_Date,'%Y-%m') AS dt FROM tbl_complaintsheet WHERE dt LIKE '2014%' GROUP BY DATE_FORMAT(c_Date, '%Y%m')
Upvotes: 2
Reputation: 31749
Try with extracting the year -
FROM tbl_complaintsheet WHERE YEAR(c_date)=2014
Upvotes: 2