Dell Released

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, August 21, 2013

How to aggregate data without group by

Posted on 2:10 PM by Unknown
How to aggregate data without group by



I am having a little bit of a situation here.

The environment

I have a database for series here. One table for the series itself, one

for the season connected to the series table, one for the episodes

connected to the seasons table. Since there are air dates for different

countries I have another table called 'series_data` which looks like the

following:

CREATE TABLE IF NOT EXISTS `episode_data` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`episode_id` int(11) NOT NULL,

`country` char(3) NOT NULL,

`title` varchar(255) NOT NULL,

`date` date NOT NULL,

`tba` tinyint(1) NOT NULL,

PRIMARY KEY (`id`),

KEY `episode_id` (`episode_id`),

KEY `date` (`date`),

KEY `country` (`country`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Now I am trying to collect the last aired episodes from each series in the

database using the following query:

SELECT

*

FROM

`episode_data` ed

WHERE

`ed`.`date` < CURDATE( ) &&

`ed`.`date` != '1970-01-01' &&

`ed`.`series_id` = 1

GROUP BY

`ed`.`country` DESC

ORDER BY

`ed`.`date` DESC

Since I have everything normalized I changed 'episode_id' with 'series_id'

to make the query less complicated.

What I am trying to accomplish

I want to have the last aired episodes for each country which are actually

announced (ed.date != '1970-01-01') as the returning result of one query.

What's the problem

I know now (searched google, found not for me working answers here), that

the ordering takes place AFTER grouping, so my "date" ordering is

completly useless.

The other problem is that the query above is working, but always takes

those entries with the lowest id matching my conditions, because those are

the first ones in the tables index.

What is the question?

How may accomplish the above. I do not know if the grouping is the right

way to do it. If there is no "one liner", I think the only way is a sub

query which I want to avoid since this is as far as I know slower than a

one liner with the right indexes set.

Hope in here is everything you need :)
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Increasing the font size of a webview conflict with UIScrollView
    Increasing the font size of a webview conflict with UIScrollView i have a UIWebView inside a UIScrollView. I am using this code to increase ...
  • FREE 50 GB of Online Storage
    The wave of future computing is portable and in the cloud. Since you are a proud owner of a Dell Streak tablet, you are already doing portab...
  • candied mints storage and transporting long distance
    candied mints storage and transporting long distance I'm making mints for my nephew's wedding (containing powdered sugar, butter, wh...
  • Dell Released Official Gingerbread Update For Streak 5
    To everyone's amazement, Dell has just released the Gingerbread update for their discontinued Streak 5. This is an official build from D...
  • Live USB quit working...HELP :-)
    Live USB quit working...HELP :-) I had 13.04 32bit running great on a Sandisk Extreme USB 3.0 64gb stick. For the most part I use it on a To...
  • I need to make my JPanel resize dynamically as new components are being added to it
    I need to make my JPanel resize dynamically as new components are being added to it I need to let users add more text fields to my JFrame so...
  • system of pde (solid mechanics)
    system of pde (solid mechanics) Please I am currently solving the following system of Partial Differential Equations as follows; -Mx/Dxy = (...
  • Restore only some volumes from a multiOS system image
    Restore only some volumes from a multiOS system image I have two Windows installations on different drives. System Restore won't let me ...
  • WordPress Guest Author - How can I use custom fields to create guest author link?
    WordPress Guest Author - How can I use custom fields to create guest author link? We are posting articles authored by guest authors. The gue...
  • Undefined symbols error from static framework
    Undefined symbols error from static framework I'm linking against a static framework in my Xcode project, but despite setting everything...

Categories

  • Games
  • News
  • Streak 5
  • Streak 7
  • Tips

Blog Archive

  • ▼  2013 (124)
    • ▼  August (124)
      • Should I make multiple SQLite databases for better...
      • Difference between Nil and nil and Null in Objecti...
      • Cannot connect to SQL Server 2012
      • Android - error opening file just created
      • PHP SimpleXML doesn't output anything
      • Memory leak (igraph, watts.strogatz.game, get.all....
      • How do I position a div on top of another div
      • Updating foreign key references on the DbContext C...
      • Convert string to DateTime and format
      • call function on click outside of a particular div
      • OperationalError when inserting into sqlite 3 in P...
      • Trying to print a string character by character wi...
      • I need to make my JPanel resize dynamically as new...
      • How to retrieve images from cache memory?
      • how to add jscrollpane to jframe?
      • Query on how to Select Date before the latest Date...
      • Does archive size of tar, zip and rar effect the t...
      • How do I make a DOM object follow a circular path ...
      • how to use for loop for my issue
      • AngularJS - Pass variable from a controller & upda...
      • Windows 2012: how to make power button work in eve...
      • IN OBOUT grid, how to move from first grid to anot...
      • Am I using the form action correctly?
      • Increasing the font size of a webview conflict wit...
      • quicktags "link" button doesn't work, but all othe...
      • Cannot access local variables using systemtap
      • Remove/avoid adding target link to URL
      • Left-justified equations with left tags (so it loo...
      • [ Marriage & Divorce ] Open Question : My boyfrien...
      • livetv2pc)))WaTch (Rugby) Australia vs New Zealand...
      • The Google Visualization API Query Language: Query...
      • iOS 7 phone-number link doesn't work when webpage ...
      • Cross-browser textarea maxlength
      • candied mints storage and transporting long distance
      • how to convert objectHTML into html
      • Mellin transform definition
      • Multiple Google Calendars with one Google Cal ID
      • Dell PowerEdge 2950 PCIe Training Error -- No PCIe...
      • Reset Disk - Windows Storage Server 2012
      • Windows Phone 8 - Keeping background location trac...
      • Django forms design suggestiom
      • Magento Upgrade, getting error with tier prices fr...
      • Bouncing between "Adapter is detached" and "No wra...
      • How to create overlapping - not stacking - shapes ...
      • Enclosing capsules around list based arrays [on hold]
      • Identifying Switch case argument (Perl)
      • asp.net ModalPopupExtender not behaving properly
      • fanotify unable monitor entire system for FAN_OPEN...
      • Jquery UI datepicker inline "onclick" handler caus...
      • URL constantly results in a badbox
      • Split values over multiple rows with different del...
      • How to aggregate data without group by
      • Angular $scope.$watch on (for in... ) don't work
      • Using Modernizr to test browser support for css ca...
      • Content overlapping in navigation menu?
      • cls file - multiple files
      • Differences between "fortification nouns"
      • filtration on the cohomology of a complex
      • Problems with every aspect of facebook that involv...
      • Extract data from last line in a text file using PHP
      • How to properly provide data for ?
      • ConditionalPanel doesn't support variables with do...
      • Frequent out of memory issues
      • Undefine reference for libraries, so How could I f...
      • radio buttons checked with jquery not holding prop...
      • How to modify bash command to change permissions
      • header(Content-type: image/jpeg) not working
      • Removing smart quotes from an SQL server text column
      • Getting out of sync server response
      • thesis work" vs "thesis
      • php radio post wrong same value after submit
      • Several questions about trigonometry and functions
      • A div that adapts to its background
      • Why are there two different versions of the mean a...
      • Restore only some volumes from a multiOS system image
      • system of pde (solid mechanics)
      • Application or Object defined error - VBA Excel 2013
      • Deleting the last few revisions: SVN best practice
      • Choose blackberry 10 platform to use call logs, me...
      • Procedure or function usp_logout has too many argu...
      • how can i use combination of unix signals (like SI...
      • Basic Javascript Countdown Timer Taking Longer Tha...
      • WordPress Guest Author - How can I use custom fiel...
      • button to generate html delete method?
      • socket.io redis ECONNREFUSED
      • Can one http request call multiple css files?
      • .htaccess related codeigniter. why error 404 page ...
      • Undefined symbols error from static framework
      • XML Sitemap Generator for URL with 1.5 million pages?
      • How do I prevent Microsoft DNS from reporting vers...
      • Solve the equation for x, y and z: $\sqrt{x-y+z}=\...
      • A basic doubt on linear dependence of vectors
      • mysql charsets, can I perform the conversion in py...
      • Mirrors Edge video settings are locked
      • Receiving null messages on android, how to fix it?
      • changing an onEdit function to run onOpen
      • Handle Multiple Form tag in asp.net page?
      • Getting click event on parent page of button in frame
      • Fix column width with tabularx
      • best software to use to make a website
      • NSLog returns (null) when logging string from anot...
      • Add express middleware for param validations
      • R "object x not found error" in calling self-defin...
      • Android Application for Registration to a website
      • How to insert multiple Facebook comment boxes on o...
      • How can I group by the difference of a column betw...
      • for loop with two integers
      • Why is unsigned integer overflow defined behavior ...
      • Using multiple SELECT statements to narrow results
      • Android: Logout system and the android lifecycle
      • how to use font awesome in own css?
      • Nested Lists in Spring Expression Language
      • Live USB quit working...HELP :-)
      • Need help in drawGradientArea
      • django-ckeditor Image Browsing
      • C3P0 connection Pooling issues
      • Code keeps entering values into array backwards
      • Number of permutations with repeated objects.
      • How do I suspend a certain process when display is...
      • How to free Watch Houston Texans vs Minnesota Viki...
      • UPS Shipping required I get a new account ID and n...
      • Java concurrency - Is this efficient?
      • Are floated element really removed from normal htm...
      • How to implement Jquery Text Editor with Hindi Lan...
  • ►  2012 (6)
    • ►  February (2)
    • ►  January (4)
  • ►  2011 (10)
    • ►  December (1)
    • ►  November (2)
    • ►  October (7)
Powered by Blogger.

About Me

Unknown
View my complete profile