chiark / gitweb /
New pared-down query for ipair_gettrades
[ypp-sc-tools.db-live.git] / yarrg / rsvalue.c
index a4e70f62a929240ecb5f20d7f38a770c227bed05..fe9c992acb4220ce9e15b5f7fb7bd1d93c7685f7 100644 (file)
@@ -1,24 +1,30 @@
 /**/
 
+typedef struct {
+  int commodid, src_price, src_qty, dst_price, dst_qty;
+} Trade;
+
+typedef struct {
+  int ntrades;
+  Trade *trades;
+} IslandPair;
+
 #include "rscommon.h"
 
 static void ipair_gettrades(int si, int di) {
   char *stmt= masprintf
     ("SELECT\n"
+     " sell.commodid           commodid,\n"
      " sell.price              src_price,\n"
      " sum(sell.qty)           src_qty,\n"
      " buy.price               dst_price,\n"
-     " sum(buy.qty)            dst_qty,\n"
-     " commods.commodid                commodid,\n"
-     " commods.unitmass                unitmass,\n"
-     " commods.unitvolume      unitvolume\n"
-     " FROM commods\n"
-     " JOIN sell ON commods.commodid = sell.commodid\n"
-     " JOIN buy  ON commods.commodid = buy.commodid\n"
-     " WHERE buy.price > sell.price\n"
-     " AND sell.islandid=%d\n"
-     " AND buy.islandid=%d\n"
-     " GROUP BY commods.commodid, sell.price, buy.price\n",
+     " sum(buy.qty)            dst_qty\n"
+     " FROM sell JOIN buy\n"
+     "   ON sell.commodid = buy.commodid\n"
+     "  AND buy.price > sell.price\n"
+     " WHERE sell.islandid=%d\n"
+     "  AND buy.islandid=%d\n"
+     " GROUP BY sell.commodid, sell.price, buy.price\n",
      si, di);
   
   printf("SQL\n[\n%s\n]\n", stmt);