sqlkata / querybuilder

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
https://sqlkata.com
MIT License
3.12k stars 502 forks source link

Need help to build sqlkata query without using "SelectRaw" and "WhereRaw" functions #514

Closed xayaraj closed 3 years ago

xayaraj commented 3 years ago

Need help to build sqlkata query without using "SelectRaw" and "WhereRaw" functions for the sql script below. The difficulty that I found is to not using sql "Date_Add" function. I am somewhat new to sqlkata library. My goal is to master this sql builder framework. Need some guidance. Thanks.

select ShipCountry, avg(Freight) as AverageFreight from northwind.orders where OrderDate >= Date_Add((select max(orderdate) from northwind.orders), interval -12 month) group by ShipCountry order by AverageFreight desc limit 3;

fairking commented 3 years ago

Long time ago I had the same question: https://github.com/sqlkata/querybuilder/issues/359 I had to write all of those helpers by myself. 100% strong type.

QueryHelper.cs: image image

Usage: image

Hope it helps

xayaraj commented 3 years ago

Wow. This should be a good starting point for me. Thank you for your help. Appreciate that.