このディレクトリの索引
http://hibari.2ch.net/test/read.cgi/db/1274791771/508
# http://www.dotup.org/uploda/www.dotup.org1202425.jpg
# 
# ItemTable
# ItemID,ItemName,Price,Maker
# --------------------------------------
# '0001','Red bollpen',150,'Four Diamond'
# '0002','Sharp pen',250,'Four Diamond'
# '0003','Metal ruler',200,'Pantel'
# '0004','Eraser',100,'Four Diamond'
# '0005','Pencil box',150,'Pantel'
# 
# 対応するPrologコードを書きなさい。
# 
%  テーブル構造(関係名,_属性番号,_属性名,_属性名の変数文字列表現).

テーブル構造('ItemTable',1,'ItemID','ItemID').
テーブル構造('ItemTable',2,'ItemName','ItemName').
テーブル構造('ItemTable',3,'Price','Price').
テーブル構造('ItemTable',4,'Maker','Maker').

'ItemTable'('0001','Red bollpen',150,'Four Diamond').
'ItemTable'('0002','Sharp pen',250,'Four Diamond').
'ItemTable'('0003','Metal ruler',200,'Pantel').
'ItemTable'('0004','Eraser',100,'Four Diamond').
'ItemTable'('0005','Pencil box',150,'Pantel').

# Q1.
# SELECT MIN(Price) AS Result FROM ItemTable;

'Q1'(Result) :-
        findmin(Price,'ItemTable'(_,_,Price,_),MIN_Price).

# Q2.
# SELECT ItemName,Price FROM ItemTable WHERE Price >= 250;

'Q2'(ItemName,Price) :-
        'ItemTable'(_,ItemName,Price,_),
        Price >= 250.

# Q3.
# SELECT MAX(Price) FROM ItemTable WHERE Maker = 'Pantel';

'Q3'(MAX_Price) :-
        findmax(Price,'ItemTable'(_,_,Price,_),MAX_Price).

# Q4.
# SELECT MIN(Price) FROM ItemTable WHERE Price > (SELECT MIN(Price) FROM ItemTable);

'Q4'(Min_Price) :-
        findmin(Price,'ItemTable'(_,_,Price,_),MIN_Price1),
        findmin(Price,(
                    'ItemTable'(_,_,Price,_),Price > MIN_Price1)),
                MIN_Price).