Jump to content

sptrsn

Members
  • Posts

    57
  • Joined

  • Last visited

Everything posted by sptrsn

  1. Barand, Thanks so much. I can make this work. How would add a sum total as at the bottom? Would you even do it in mysql? If I'm doing this in a vacuum, I would probably use javascript just do it in the browser. And at which point would you convert from int to date format?
  2. Sorry. Got distracted and forgot to include table info. Here is the create with a little test data. And here is a simplified version of the query. (fewer fields. If I can make this work... I can add the additional columns) select * from ( select `date`, sum(created) created, sum(offers) offers from ( select DATE(from_unixtime(created)) `date`, 0 as created, 0 as offers from properties union all select DATE(from_unixtime(created)) `date`, count(*) created, 0 as offers from properties union all select DATE(from_unixtime(offer_date)) `date`, 0 as created, count(*) as offers from properties )a group by `date` )b CREATE TABLE IF NOT EXISTS `properties` ( `id` int(11) NOT NULL AUTO_INCREMENT, `created` int(11) NOT NULL DEFAULT '0', `offer_date` int(11) NOT NULL DEFAULT '0', `contract_date` int(11) NOT NULL DEFAULT '0', `purchase_date` int(11) NOT NULL DEFAULT '0', `sale_date` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; INSERT INTO `properties` (`id`, `created`, `offer_date`, `contract_date`, `purchase_date`, `sale_date`) VALUES (1, 1441065600, 1441152000, 1441238400, 1442016000, 1442534400), (2, 1441152000, 1441152000, 1441324800, 1445817600, 1450137600), (3, 1441238400, 1441324800, 1441324800, 1444953600, 1451433600), (4, 1441324800, 1441324800, 1441324800, 1446768000, 1452816000), (5, 1441411200, 1441411200, 1441411200, 1448928000, 1454284800);
  3. I'm stuck like a wheel barrow in the mud. Wondering if someone might be able to help me write this query. I have a table where status change dates are held. I'm trying to build a query that sums each of the columns by date. In the end.... I should have a column of dates in the first column. several columns as listed below. (created, offers, contracts, closed, sold) Then the total number of records with dates that match the row date. (It think that makes sense) So I can tell ... how many records were created on each day. how many offers were made on each day etc etc. Here is the query I have so far which doesn't quite work. Display is attached. select * from ( select `date`, sum(created) created, sum(offers) offers, sum(contracts) contracts, sum(closed) closed, sum(sold) sold from ( select DATE(from_unixtime(created)) `date`, count(*) created, 0 as offers, 0 as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(offer_date)) `date`, 0 as created, count(*) as offers, 0 as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(contract_date)) `date`, 0 as created, 0 as offers, count(*) as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(purchase_date)) `date`, 0 as created, 0 as offers, 0 as contracts, count(*) as closed, 0 as sold from properties union all select DATE(from_unixtime(sale_date)) `date`, 0 as created, 0 as offers, 0 as contracts, 0 as closed, count(*) as sold from properties )a group by a.`date` )b
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.