I have a table “record” with the columns: How do I write query that will list the userId and month for any occasions where a user logged in more than 10 times in a month? Answer Assuming your record table as an entry per login. The query is relatively straight forward (here using PostgresSQL speci…
How do I write SQL query for the website traffic
I have a table record with the columns: How do I write a query that will list the site traffic per month (measured in # of logins) from January 2017 through December 2017 Answer You can use group by as follows:
How to check if a customer has made a warranty claim and a product sale?
I would like to know how to check in PostgreSQL to see if whether or not a customer has made both a warranty claim and a product sale. For example , I have a customer like this. CustomerID OrderID Product Name ABC123 1426457 PRODUCT A ABC123 1426458 WARRANTY CLAIM So for this customer. I want to set a column …
can we simplify “while” inside of “while”?
i need some little help ,,, I have a data like this.., (I use php mysql) Initially there was no problem with this, but as time goes by, my data is getting bigger and bigger. finally its made my program slow .. I think maybe because I used “while” inside of “while”. make SQL is called m…
MySQL: Updating multiple columns using if else
I need help to set a mySQL update query for my little project like below: In my table, there is a column REFERENCE which contains varchar like where the character before the symbol ‘_’ determines certain values for other columns like stated above. I am still fairly new to mySQL, so appreciates any…
Normalize dates to periods starting at same origin
I’m attempting to track the evolution of customer spending over time. Essentially, I need to identify the first instance of customer purchase, assign it a rank of 1, and assign all of their purchases …
Replace values for each ID and each month in IBM DB2 SQL?
I have about several milion record table in IBM DB2 with 4 columns: yeas, month, personal_number (2 milion), personal_id. The key is that I want to get same table from this one, but I want to fill in personal_id column value from last month (in all previous months). Point is to get 1-1: 1 personal_id relate t…
Fastest way to get the max date in SQL database (Azure)
I have a table that has Many rows up to 1000000. and 300 columns Question : I would like to know the fastest way to get the max date of the column ‘LastModifiedDate in table. In My table I have the columns : Id, LastModifiedDate and others columns… Thanks in advance for your help Answer If the ins…
Using the Like operator with two fields
How do I use the Like operator to join two unidentical tables as below? My main problem is on how to compare the PO filed on tbl2 to the EditNo on tbl1 field. Please see sample tables and expected results below: tbl1: tbl2: Expected: Query: SELECT * FROM tbl2 INNER JOIN tbl1 ON tbl2.PONo LIKE EditNo.PO; Answe…
Order by a subtraction expression sql
I would like to perform an ORDER BY in sql that sorts the returned rows by their distance from my integer of interest. The expression would be ORDER BY (constant – ColumnName) ASC specifically, something like ORDER BY (10 – Distance) ASC. When I tried running this expression the distances were jus…