表聯賽子查詢或加入MySQL?
team_id name wins losses played recorded created
1 dodgers 10 4 14 1364790000 1353215830
2 angels 9 6 15 1364790000 1353661376
3 pirates 12 3 15 1364790000 1353543466
team_id name wins losses played recorded created
1 dodgers 22 9 31 1367274480 1353215830
2 angels 14 17 31 1367274480 1353661376
3 pirates 19 13 32 1367274480 1353543466
4 yankees 10 9 19 1367274480 1365577298
5 brewers 7 11 18 1367274480 1365394448
想結果爲:
team_id name wins losses played
1 dodgers 12 5 17
2 angels 5 11 16
3 pirates 7 10 17
4 yankees 10 9 19
5 brewers 7 11 18
我試過幾個查詢連接並沒有成功。每一天,球隊都會獲得勝利,失敗並參加比賽,並在錄製的專欄上記錄時間標記。該團隊創建在創建的列上。 (所有unix時間戳)我想要的2個日期之間有幾行,但我不需要它們進行此查詢。
我想要做的是讓四月的韓元/丟失/效力於現有的和新的球隊,我試了幾個疑問,這裏有一對夫婦沒有給我想要的結果:
SELECT a.name as name, a.wins-b.wins as wins, a.losses-b.losses as losses, a.played-b.played as played from league a join league b on a.id=b.id where a.recorded= 1367274480 and b.recorded= 1364790000
和
SELECT new.*, new.wins-old.wins as newwins, new.losses-old.losses as newlosses FROM league new LEFT JOIN league old ON new.id=old.id WHERE (new.recorded=1367274480 and old.recorded=1364790000) or (new.created > 1364790000 and new.recorded=1367274480) GROUP BY new.id
什麼數據類型用於'錄製'和'創建'列?他們是否應該是某種日期時間表示? – 2013-05-01 01:50:14
它們是存儲爲int的日期的unix_timestamp()版本。 – piotrm 2013-05-01 02:30:38
我知道,我希望「時間戳」是** NOT **日期時間值,但是是支持樂觀鎖定的引用計數器。它不能用於可靠地重新生成日期時間。 – 2013-05-01 02:36:34