Skip to content

Tag: sql

sql query to fetch exchange rate

Given a sales table with sales amount stored in local currencies and an exchange rate table containing currency conversion rate, to get total sales amount in USD for each sales date I need query Sales Table: Exchange Rate Table: have no idea how I should proceed I have to do two things match the currency and …

Max Value based on two columns

I have a table with multiple columns that contains both month and year. I’m trying to identify based on column1,column2 what is the greatest month and year. I have a DDL for a test table as such. This is the data in the example table. I want to get the record with the max month and year. When I attempt

How to verify SqlAlchemy engine object

I can declare engine object with the invalid username, password or address and get no exception or error: it prints likes it is a valid engine object: What would be a common way to verify (to check) if the engine object is valid or if it is “connectable” to db? Answer Question: How to verify if th…

Mysql Sum daily totals into weekly totals for given date range

Currently my db table has dailTotal values for every single day, I need to get these grouped into weekly totals. Is it possible to add the daily totals up into weekly totals and display a row each weekly total between the given date range. Im not quite sure where to start with this one. My current query to ge…

Using ‘LIKE’ and ‘REGEXP’ in a SQL query

I’m trying to use some regex on an expression where I have two conditions on the WHERE clause. The pattern I want to capture is 106 followed by any digit followed by a digit that must be either 3 or 4, i.e. 106[0-9][3-4] First, I tried this: This produced an error as below and it would be good to know

CONVERT issue in sqlserver with Msg 529 error

This statement is giving me a error VALUE column Datatype is TEXT in the RESULTS table. How can i overcome the above problem. please help ! Answer You can’t convert from text to datetime You must apply two convert operations. The first: From text to varchar The second: From varchar to datetime So your q…