Jump to content
php.lv forumi

collon type: TIME + sum


anonīms

Recommended Posts

mysql> SELECT CAST(CAST('18:15:00' AS time)+CAST('05:02:00' AS time) AS time);
+-----------------------------------------------------------------+
| CAST(CAST('18:15:00' AS time)+CAST('05:02:00' AS time) AS time) |
+-----------------------------------------------------------------+
| 23:17:00                                                        |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)

Link to comment
Share on other sites

Laikam esmu kkur kko nolaidis grieizi. Neizvadās 'time'

    $kaarta1 = mysql_query("SELECT t1.*, CAST(CAST(t1.trase1 AS time)+CAST(t1.trase2 AS time)+CAST(t1.trase3 AS time)+CAST(t1.trase4 AS time)+CAST(t1.trase5 AS time)+CAST(t1.trase6 AS time) AS time) AS time, t2.lietotajvards AS users FROM ".PREFIX."racing_rezultati AS t1, ".PREFIX."lietotaji AS t2 
   WHERE t1.t_id = '".$tourney['id']."' AND t1.user_id = t2.id AND t1.karta = 1
   ORDER BY time ASC") or die(mysql_error());

Link to comment
Share on other sites

CREATE TABLE IF NOT EXISTS `racing_rezultati` (
 `id` int(11) NOT NULL auto_increment,
 `t_id` int(11) NOT NULL,
 `user_id` int(11) NOT NULL,
 `trase1` time NOT NULL,
 `trase2` time NOT NULL,
 `trase3` time NOT NULL,
 `trase4` time NOT NULL,
 `trase5` time NOT NULL,
 `trase6` time NOT NULL,
 `karta` tinyint(1) NOT NULL default '1',
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;

--
-- Dumping data for table `bliezamv3_racing_rezultati`
--

INSERT INTO `racing_rezultati` (`id`, `t_id`, `user_id`, `trase1`, `trase2`, `trase3`, `trase4`, `trase5`, `trase6`, `karta`) VALUES
(1, 523, 1, '00:18:15', '00:05:02', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(2, 523, 147, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(3, 523, 349, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(4, 523, 145, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(5, 523, 159, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(6, 523, 198, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(7, 523, 405, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1),
(8, 523, 115, '00:23:18', '00:05:43', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1);

Link to comment
Share on other sites

Laikam esmu kkur kko nolaidis grieizi. Neizvadās 'time'

jaa taa tiesham irt1.trase1 AS time)+CAST(t1.trase2 AS time)+CAST(t1.trase3 AS time)+CAST(t1.trase4 AS time)+CAST(t1.trase5 AS time)+CAST(t1.trase6 AS time) AS time) AS time

Alias cik reizas atkartojas ??

To var izmantot tikai vienu reizi (tas ir vienu nosukumu ),

tev pat atkartojas 8 !! reizes

Piedevam time ir rezervets vards, labak to neizmantot

Edited by Grey_Wolf
Link to comment
Share on other sites

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'laiks1)+CAST(t1.trase2 AS laiks2)+CAST(t1.trase3 AS laiks3)+CAST(t1.trase4 AS la' at line 1

:/

kādēļ neļauj tādus aliasus? ieliku atpakaļ time, tā uzreiz errors rādas no nākamā alias.

SELECT t1.*, CAST(CAST(t1.trase1 AS laiks1)+CAST(t1.trase2 AS laiks2)+CAST(t1.trase3 AS laiks3)+CAST(t1.trase4 AS laiks4)+CAST(t1.trase5 AS laiks5)+CAST(t1.trase6 AS laiks6) AS laiks_laiks) AS trashu_laiks, t2.lietotajvards AS users FROM ".PREFIX."racing_rezultati AS t1, ".PREFIX."lietotaji AS t2 
   WHERE t1.t_id = '".$tourney['id']."' AND t1.user_id = t2.id AND t1.karta = 1
   ORDER BY trashu_laiks ASC

Link to comment
Share on other sites

biskji parsteidzos :( (nogurums .. )

ieksh CAST tieshi janorada datu tips..

nevar izmantot vienkarshi ieksh alias ..

tas ir piemeram xx AS time, vai ORDER BY time

--

tapec parasti rakstot kverijus visam funkcijam etc,jacenshas izmantot lielie burti , mazie lai paliek nosaukumiem ...

Link to comment
Share on other sites

MySQL tomēr līdz galam nav pārdomājis laika saskaitīšanu :) Risinājums: pārvēršam laiku sekundēs, saskaitam un saskaitītās sekundes pārtaisam atpakaļ uz laiku:

mysql> SELECT *, SEC_TO_TIME(TIME_TO_SEC(`trase1`)+TIME_TO_SEC(`trase2`)+TIME_TO_SEC(`trase3`)+TIME_TO_SEC(`trase4`)+TIME_TO_SEC(`trase5`)+TIME_TO_SEC(`trase6`)) AS `total_time` FROM `racing_rezultati`;
+----+------+---------+----------+----------+----------+----------+----------+----------+-------+------------+
| id | t_id | user_id | trase1   | trase2   | trase3   | trase4   | trase5   | trase6   | karta | total_time |
+----+------+---------+----------+----------+----------+----------+----------+----------+-------+------------+
|  1 |  523 |       1 | 00:18:15 | 00:05:02 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:23:17   |
|  2 |  523 |     147 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:00:00   |
|  3 |  523 |     349 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:00:00   |
|  4 |  523 |     145 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:00:00   |
|  5 |  523 |     159 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:00:00   |
|  6 |  523 |     198 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:00:00   |
|  7 |  523 |     405 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:00:00   |
|  8 |  523 |     115 | 00:23:18 | 00:05:43 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 |     1 | 00:29:01   |
+----+------+---------+----------+----------+----------+----------+----------+----------+-------+------------+
8 rows in set (0.00 sec)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...