Additional SQL Server features and topics not covered by specific categories
You can try the below script
#connect the db server
conn = pyodbc.connect(
"Driver={SQL Server Native Client 11.0};"
"Server=yourserver;"
"Database=yourdb;"
"UID=username;"
"PWD=password;"
"Trusted_Connection=no"
)
#To execute queries, the “cursor()” object of the connection object is used. The following script stores the cursor object in the “cursor” variable:
cursor = conn.cursor()
select_record = '''select
convert(date,create_t) as create_t,count(ordernumber) as ordercount
from yourtable
where create_t>='2023-03-01'
group by convert(date,create_t) '''
sql_query =pd.read_sql_query(select_record,conn)
cursor.execute(select_record)
df = pd.DataFrame(sql_query, columns = ['create_t', 'ordercount'])
print (df)