Skip to content
Advertisement

Tag: sql-server

SQL: Select MAX value from 2 conditions

I have 1 table and 4 columns. I would like to get max value from visit and spending with use condition as max visit first and max spending second. The result should be shown on the YELLOW highlight on Image above. For my code below. Please help me in a better way to do this. Answer This would be the

Select the duplicate rows with specific values

How can I only get the data with the same ID, but not the same Name? The following is the example to explain my thought. Thanks. Expected Output: How I have done. But the result included the following parts that I do not want it. Answer One approach would be to use a subquery to identify IDs that have multiple

Default sort my own order without sort by

I want to leave the order as is in the in Clause, however SQL output is ordered by ID I know how to achieve the result using a temp table. Is there a better way to do it? Answer Not sure what you mean by I know how to achieve the result using a temp table as you haven’t shown

Knex join on column belonging to same same table

Using Knex.js, I am attempting to query a table of users. The only columns that are important for this scenario are internal_id (key), name, and supervisor_id. Every user (except one) has a supervisor and their record stored the ID of that supervisor. When viewing an individual user record in my app, I want to query the users table getting info

Converting nvarchar to int, converting phone with symbols with only numbers

I am trying to convert phone number from the column ‘phone’ from the table ‘Clients’. I have tried the following syntaxes, but I still get error messages – Error: Conversion failed when converting the nvarchar value ‘030-3456789’ to data type int Conversion failed when converting the nvarchar value ‘030-3456789’ to data type int. The query doesn’t return error but there

Get records greater than 1 for same status

I have table logs Table 2 status_master So, now I’m trying to get the retry count for each scenario. Expected result Answer Sounds like an aggregation of an aggregation to me. Try: Results status count 2 1 19 1 My results were different than your expected results. Did you mean for status = 1 to be status = 2 in

Copy data from one set of tables to another with extra columns [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago. Improve this question Is there any quick way for the below one? instead of generating Insert into Select SQL queries manually one by one for all 500 tables?

Advertisement