Commit f4a8e7e9 authored by cividesk's avatar cividesk

StackExchange: minor fixes in queries

parent 9530c067
......@@ -4,16 +4,20 @@ require_once('stackapi.php');
$queries[] = array(
'file' => 'stackexchange-info.json',
'query' => "
SELECT " . implode(', ', $se_fields['site']) ."
SELECT " . implode(',', $se_fields['site']) ."
FROM stackexchange_history
ORDER BY date DESC
ORDER BY ts_created DESC
LIMIT 1
",
);
$fields = array();
foreach ($se_fields['site'] as $field) {
$fields[] = "MAX($field) AS $field";
}
$queries[] = array(
'file' => 'stackexchange-history.json',
'query' => "
SELECT LEFT(ts_created, 7) AS month, MAX(". implode('), MAX(', $se_fields['site']) . ")
SELECT LEFT(ts_created, 7) AS month,". implode(',', $fields) . "
FROM stackexchange_history
ORDER BY month ASC
",
......@@ -21,7 +25,7 @@ $queries[] = array(
$queries[] = array(
'file' => 'stackexchange-top-users-by-reputation.json',
'query' => "
SELECT display_name, COALESCE(location, ''), reputation
SELECT display_name, COALESCE(location, '') AS location, reputation
FROM stackexchange_users
ORDER BY reputation DESC
LIMIT 100
......@@ -30,7 +34,7 @@ $queries[] = array(
$queries[] = array(
'file' => 'stackexchange-top-users-by-accept-rate.json',
'query' => "
SELECT display_name, COALESCE(location, ''), accept_rate
SELECT display_name, COALESCE(location, '') AS location, accept_rate
FROM stackexchange_users
ORDER BY accept_rate DESC
LIMIT 100
......@@ -39,7 +43,7 @@ $queries[] = array(
$queries[] = array(
'file' => 'stackexchange-top-users-by-badges.json',
'query' => "
SELECT display_name, COALESCE(location, ''), badges_gold, badges_silver, badges_bronze
SELECT display_name, COALESCE(location, '') AS location, badges_gold, badges_silver, badges_bronze
FROM stackexchange_users
ORDER BY badges_gold DESC, badges_silver DESC, badges_bronze DESC
LIMIT 100
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment