mysql - sql group by with group condition -
i have product table like:
id p_name s_date 1 2014-10-10 2 b 2014-10-02 3 2014-10-08 4 2014-10-11 5 b 2014-10-08
i need grouping on p_name. query
select * product grouping p_name;
this query retrieving record 1 , 2. need check p_date
current date when grouping on p_name
. if current date '2014-10-11' need record 4 product grouping 'a' because record 4 matched current date , record 2 product grouping 'b' because no 1 of p_name 'b' matched current date. query check p_date
current date when grouping on p_name
. need retrieve record grouping matched current date, if no record matched current date record of minimum date.
maybe can have check mysql having clause.. , modify query like...
select * product grouping p_name having p_date = curdate();
mysql sql
No comments:
Post a Comment