13
votes
4answers
21k views

mysql select sum group by date

Quick question, I have the following table +-------------+---------------------+ | total | o_date | +-------------+---------------------+ | 35 | 01-11-2009 19:32:44 | | ...
11
votes
5answers
26k views

mysql query: SELECT DISTINCT column1, GROUP BY column2

Right now I have the following query: SELECT name, COUNT(name), time, price, ip, SUM(price) FROM tablename WHERE time >= $yesterday AND time <$today GROUP BY name And what I'd like ...
10
votes
7answers
536 views

SQL “GROUP BY” issue

I'm designing a shopping cart. To circumvent the problem of old invoices showing inaccurate pricing after a product's price gets changed, I moved the price field from the Product table into a ...
7
votes
6answers
119 views

SQL limit for LEFT JOINed table

I have the following tables. Industry(id, name) Movie(id, name, industry_id) [Industry has many movies] Trailer(id, name, movie_id) [Movie has many trailers] I need to find 6 latest trailers for ...
6
votes
2answers
6k views

SQL Server GROUP BY datetime ignore hour minute and a select with a date and sum value

I have a table with two fields - datetime and int. I want to do a group by on the datetime only on the date ignoring the hour and minute. The SELECT statement should return a date that maps to the sum ...
6
votes
3answers
3k views

count total records after groupBy select

I have a mysql select query that has a groupBy. I want to count all the records after the group by statement. Is there a way for this directly from mysql ? thanks.
6
votes
2answers
393 views

GROUP_CONCAT() row count when grouping by a text field

DROP TABLE IF EXISTS `table`; CREATE TABLE `table` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM ...
6
votes
2answers
239 views

MySQL SELECT multiple rows based on specific field value and number of rows

I have three tables: author (columns: aut_id, aut_name) book (columns: book_id, book_title) authorbook (linking table, columns: aut_id, book_id) Each author can be associated with one or more ...
5
votes
1answer
12k views

LINQ: Selecting items from a list (Group By/Select/Sum & Max!)

Just getting my head around Linq and having lots of fun! Can any one aid me with a query for this: I have a list of data: Key Value Aaa 12 AaA 10 AAa 5 BBB 2 Bbb 1 1. I ...
5
votes
2answers
133 views

Mysql Get Rank with Filters

I Have a marksheet table like: ID STUDENT_ID Branch_id Class_id Exam_id Subject_id Numbers Date 1 653 5 1 1 8 60 2012-01-01 2 ...
5
votes
1answer
160 views

Retrieve an arbitrary number of random rows from each 'group by' category in MySQL

I have a table in MySQL that contains a column name category. I am trying to write a query that will return 2 random records from each category. Here is code that I use to get 2 records from each ...
4
votes
2answers
1k views

MySQL - sum column value(s) based on row from the same table

I'm trying to get 'Cash', 'Check' and 'Credit Card' totals in new columns based on ProductID from the same table. Table - Payments +-----------+------------+---------------+--------+ | ProductID | ...
4
votes
1answer
146 views

MYSQL sum the total up and down votes by all users for the items bought by a single user

I'd like to sum the total up and down votes on only the items bought by a single user. I have a big table so I don't want to sum all votes made by everyone for EVERY item, just the items that a ...
3
votes
2answers
2k views

MYSQL shows incorrect rows when using GROUP BY

I have two tables: article('id', 'ticket_id', 'incoming_time', 'to', 'from', 'message') ticket('id', 'queue_id') where tickets represent a thread of emails between support staff and customers, and ...
3
votes
2answers
86 views

SQL : a GROUP BY issue in MySQL

Here is the database table ╔════╦═════════════╦══════════════════╦═══════╗ ║ id ║ customer_id ║ last_seen ║ param ║ ╠════╬═════════════╬══════════════════╬═══════╣ ║ 1 ║ 12345 ║ ...

1 2 3 4 5 14
15 30 50 per page