|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I have this sql statement
SELECT requirement_id , date , sum(length) as length FROM booking WHERE user_id=36 AND date >= (select subdate(inputdate, mod(dayofweek(inputdate)+5,7)) FROM (select adddate('2007-09-05',1) as inputdate) AS start) AND date <= (select subdate(inputdate, mod(dayofweek(inputdate)+6,7)) FROM (select adddate('2007-09-05',7) as inputdate) AS end) GROUP BY date, requirement_id ORDER by date desc when run it returns me for result rows, if i then wrap this in SELECT * FROM (subquery) tb as below it returns no rows. SELECT * FROM ( SELECT requirement_id , date , sum(length) as length FROM booking WHERE user_id=36 AND date >= (select subdate(inputdate, mod(dayofweek(inputdate) +5,7)) FROM (select adddate('2007-09-05',1) as inputdate) AS start) AND date <= (select subdate(inputdate, mod(dayofweek(inputdate) +6,7)) FROM (select adddate('2007-09-05',7) as inputdate) AS end) GROUP BY date, requirement_id ORDER by date desc ) tb I am doing things in this manner so i can use joins on a pre-grouped data set. Any suggestions would be great. Bam |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 12 Oct, 11:02, bamrobe...@gmail.com wrote:
> I have this sql statement > > SELECT requirement_id > , date > , sum(length) as length > FROM booking > WHERE user_id=36 > AND date >= (select subdate(inputdate, mod(dayofweek(inputdate)+5,7)) > FROM (select adddate('2007-09-05',1) as inputdate) AS start) > AND date <= (select subdate(inputdate, mod(dayofweek(inputdate)+6,7)) > FROM (select adddate('2007-09-05',7) as inputdate) AS end) > GROUP BY date, requirement_id > ORDER by date desc > > when run it returns me for result rows, if i then wrap this in SELECT > * FROM (subquery) tb as below it returns no rows. > > SELECT * FROM ( > SELECT requirement_id > , date > , sum(length) as length > FROM booking > WHERE user_id=36 > AND date >= (select subdate(inputdate, mod(dayofweek(inputdate) > +5,7)) FROM (select adddate('2007-09-05',1) as inputdate) AS start) > AND date <= (select subdate(inputdate, mod(dayofweek(inputdate) > +6,7)) FROM (select adddate('2007-09-05',7) as inputdate) AS end) > GROUP BY date, requirement_id > ORDER by date desc > ) tb > > I am doing things in this manner so i can use joins on a pre-grouped > data set. Any suggestions would be great. > Bam I'm having trouble figuring out why you need all these subqueries in the first place. How about telling us what you need to achieve and maybe we can suggest a far simpler way to do it. |
|
![]() |
| Outils de la discussion | |
|
|