I want to pass table name into into a scalar variable @Table_Name as a string. But I am getting error as: Must declare the table variable @Table_Name. How to achieve the same? Below is my code snippet: Answer So I created a temporary table using the input provided by the user and used that temp table in the q…
Tag: sql
Group by not getting the expected results in mysql
I have the next query: That is working perfectly and returning 9 rows: I want to group the results by boat type and get the number of boats per type. However, when I do: I´m getting: but according to the first query, I´m expecting What am I missing? Answer I suspect that you want: That is: move the DISTINCT w…
SQL – Get the antepenultimate (before previous group/phase)
I have the following table and I’d like to get the antepenultimate or the value before the previous value. I already have group, value and prev_value, dateint… I’m trying to derive prev_prev_value This is the table with test data (as a CTE) Any ideas on how to derive prev_prev_value I’…
How to return only one row per course
I am trying to return a list of course IDs that contain three components: assignments, discussions, and a syllabus. I want my results to have only one row per course ID with either Y’s or N’s …
using condition for Group_Concat
I want to find all ids of which group_concat only contains ‘a’. Here is simplified table from mine. ╔════╦══════════════╦ ║ id ║ group_concat ║ ╠════╬══════════════╬ ║ 1 ║ a,b,b ║ ║ 2 ║ a …
MySQL – Select on varchar column with 0 (zero) as criteria returns all rows?
Sorry in advance – this seems like a really dumb question. But… If I run a select query on a varchar() column, but use zero for the column value in the where clause – why does it return all rows? …
php mssql next row
I need some advice how to get the next value of a row with while loop in php-mssql. same articles My code:
SQL QUERY : Find for each year copies sold > 10000
I am practicing a bit with SQL and I came across this exercise: Consider the following database relating to albums, singers and sales: Album (Code, Singer, Title) Sales (Album, Year, CopiesSold) …
Find total count and average based of values from another table
In Mysql: I have customer name (primary key), cities and an amount in table: Table Cities: customer location amount Cust1 New York, USA 200 Cust2 New York, USA 300 …
left join not working or maybe I don’t know how to use it
I’m trying to generate a query with left join. The idea is that I can get: Because I need only rows that have same columnA (job), with different columnB (bat). I’m trying with left join but it is not working. Could you help me why my sql sentence is wrong? Answer GROUPBY with COUNT() will get you …