SELECT `t1`.`code`, `t1`.`name`, `t1`.`max_int1`, `t2`.`name`, `t2`.`max_int2`
FROM (
SELECT `t`.`name` AS `name`, `t`.`code` AS `code`, `t`.`int1` AS `max_int1`
FROM (
SELECT `code`, MAX(`int1`) AS `int1`
FROM `table` WHERE `city`= :city GROUP BY `code`
) AS `m`
JOIN `table` AS `t` ON `t`.`city` = :city AND `t`.`code` = `m`.`code`
AND `t`.`int1` = `m`.`int1`
) AS `t1`
JOIN (
SELECT `t`.`name` AS `name`, `t`.`code` AS `code`, `t`.`int2` AS `max_int2`
FROM (
SELECT `code`, MAX(`int2`) AS `int2`
FROM `table` WHERE `city`= :city GROUP BY `code`
) AS `m`
JOIN `table` AS `t` ON `t`.`city` = :city AND `t`.`code` = `m`.`code`
AND `t`.`int2` = `m`.`int2`
) AS `t2` ON `t1`.`code` = `t2`.`code`
#pragma pack(push,1)
typedef _websocketPacket {
unsigned char one; // здесь ваша 1
unsigned char indexElement;
unsigned char rest[18];
} wsPacket;
#pragma pack(pop)
wsPacket myData;
if (preg_match_all('/(\d\d)(\S{3})\s+\S+\s+\d+\s+(\S{3})-.*?(\d\d)(\d\d)\s+(\S{3})-.*?ARRIVAL:(\d\d)(\d\d)(?: (\d\d)(\S{3}))?/s',
$data, $matches, PREG_SET_ORDER)) {
foreach($matches as $flight) {
if (!isset($flight[9])) {
$flight[9] = $flight[1];
$flight[10] = $flight[2];
}
list($full, $depDay, $depMonth, $depIATA, $depHour, $depMin,
$arrIATA, $arrHour, $arrMin, $arrDay, $arrMonth) = $flight;
print "$depDay $depMonth $depHour:$depMin $depIATA => $arrDay $arrMonth $arrHour:$arrMin $arrIATA\n";
}
}
SELECT `r`.`recipe_id`
FROM (
SELECT `recipe_id`, COUNT(*) AS `count`
FROM `flavour_recipe`
GROUP BY `recipe_id`
) AS `r`
JOIN (
SELECT `r`.`recipe_id` AS `recipe_id`, COUNT(*) AS `count`
FROM `flavour_user` AS `u`
JOIN `flavour_recipe` AS `r` ON `u`.`user_id` = :userId
AND `r`.`flavour_id` = `u`.`flavour_id`
GROUP BY `r`.`recipe_id`
) AS `f` ON `f`.`recipe_id` = `r`.`recipe_id` AND `f`.`count` = `r`.`count`
var m = [['Euroshop', 2500, 7500],
['Euroshop', 2500, 7500],
['Tur', 2500, 7500]];
var temp = m.reduce(function(prev, el) {
if (prev.hasOwnProperty([el[0]]))
prev[el[0]] = [prev[el[0]][0]+el[1], prev[el[0]][1]+el[2]];
else
prev[el[0]] = [el[1], el[2]];
return prev;
}, {});
console.log(temp);
var result = [];
for (var name in temp)
result.push(name, temp[name][0], temp[name][1]);
console.log(result);