SELECT distinct [[shipment_requests.*]],[[shippingaddress.*]],[[billingaddress.*]],[[orders.*]],[[rep_infos.*]],[[warehouses.*]]
FROM warehouses INNER JOIN
(select top {2} * from shipment_requests where warehouse_id={0} and shipment_requests.status_code='{1}') shipment_requests ON warehouses.id = shipment_requests.warehouse_id INNER JOIN
shipment_request_line_items ON shipment_requests.id = shipment_request_line_items.shipment_request_id LEFT JOIN
comments ON shipment_requests.id=comments.shipment_request_id LEFT JOIN
orders ON shipment_requests.order_id = orders.id LEFT JOIN
order_line_items ON orders.id=order_line_items.order_id INNER JOIN
rep_infos ON shipment_requests.rep_info_id=rep_infos.id INNER JOIN
addresses shippingaddress ON shipment_requests.shipping_address_id = shippingaddress.id INNER JOIN
addresses billingaddress ON shipment_requests.billing_address_id = billingaddress.id
1、这里为什么用两层方括号?
2、我在一个C#程序里面读这个SQL语句,单步跟踪后,发现[...]变成了{...}这又是为什么?
3、(select top {2} * from shipment_requests where warehouse_id={0} and shipment_requests.status_code='{1}') shipment_requests 这里面shipment_requests 这块一直报错,是不是因为shipment_requests是表名了,所以不能再用这个名称了?
使用表的别名 shipment_requests 别名为 s_r
这种情况,不可以用表名了?
@xulonghua219:
然后SELECT distinct [[shipment_requests.*]],[[shippingaddress.*]],[[billingaddress.*]]....
就可以还成别名的
SELECT distinct s_r.*,sadd.*,badd.*....
hibernate内部还有替换。