/**/
+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);