All Questions
135 questions
1
vote
0
answers
77
views
Based on value of the present table column, get the data from another table in sql
I am trying to write a sql query to list all the users along with vendor info.
In tbl_users table, column vendor_type can have only company or agency and i am storing
the company_id or agency_id in ...
0
votes
0
answers
42
views
Multiple select count with multiple condition in MYSQL
I have 2 table customer and appointment:
Customer as:
id
fullname
created_day
province_id
1
Tom
2023-12-25
1
2
Jerry
2023-11-22
2
...
Appointment as:
id
customer_id
appointment_date
accepted
1
1
2023-...
0
votes
3
answers
99
views
MYSQL SELECT but with conditions
Is it possible within a MYSQL SELECT statement to include conditions dependent on user selection? Edited for clarity.
Something that does this:
IF user *does A* SELECT * FROM myTable
IF user *does B* ...
0
votes
1
answer
50
views
Select Multiple Columns based on multiple columns from same table in MySql
I want to return 3 columns Dtls (Details), Purchase_amount as credit, Sale_amount as debit
But When Purchase_id = 3, Purchase_amount must be selected and Sale_amount must be 0, and vice-versa.
The ...
-1
votes
1
answer
30
views
SELECT CASE doesn't proceed to next condition
I have a table with orders and my task is to output orders with status "complete" as well as all of orders grouped by that status:
select (case
when o.status = "complete" then '...
0
votes
0
answers
33
views
How CASE or select if cab be used based on some conistion to fetch data from diffrent table in mysql
there are two tables suppose (t1 and t2)
based on the constant condition I want to fetch data from different table
txn is a predefined value
I want something like this
like: if txn=0 (select * from ...
1
vote
2
answers
226
views
How can I create a column whose entries depend on the contents of a column in another table?
I have a database with multiple tables, and I want to add a column to one table that will be populated with different strings based on the contents of another table.
Below are the tables of interest.
...
0
votes
1
answer
48
views
Not filter correcting when I’m added case for the sql query
In my sql table, when I select data by using this query,
SELECT * FROM agreement_id, hierarchy_id, customer_no FROM rebate_agreement
WHERE Customer_no = 'Kap-ST';
While I use the above query it ...
1
vote
1
answer
37
views
Get CASE NUMBER printed for WHEN ORDER BY Clause in MYSQL
Is there a way to know (or at least print) which WHEN CASE got executed for which result from MYSQL query?
for e.g., I have the following SQL which gives a priority order for the ORDER by clause.
...
0
votes
1
answer
2k
views
how to use CASE statement in MYSQL to select a row from results based on condition?
I am new to sql. I have a SELECT query that returns 2 rows which have a rid (1 in both rows) and a path column which has binary value 0 or 1 I want to use a CASE statement such that it will SELECT one ...
0
votes
2
answers
58
views
Conditional Select in View - MYSQL
I have a view that needs to show the converted price of items.
I have 2 tables to join from Item_Price & FX_Rate
Simplified example:
Item table with millions of data
IP.ITEM
Item_Price.PRICE
...
-1
votes
1
answer
653
views
How to create/add a column as a return output in an SQL select query based on another column's values?
I have dynamically added a column (industry_type) to a SQL view using Case statement. Now I would like to use that same column name/values to add another dynamic column with industry_group output. I ...
-1
votes
1
answer
1k
views
MySQL Workbench - SELECT is not valid at this position with this server version when using CASE WHEN statement [closed]
When implementing a basic CASE WHEN statement in MySQL Workbench, I am getting the following error "SELECT is not valid at this position for this server version. Expecting FOR, LOCK, TABLES, ...
1
vote
1
answer
121
views
How to place a discount on a certain category of goods?
I have two tables:
categories products
CatID | Name ProdID | CatFK | Model | Price |Name
I have some categories of products like Sofas, Tables ...
0
votes
2
answers
49
views
Case expression from another case expression
I have sample of SQL code, that returns number of weeks
,CASE WHEN dateadd(MONTH, datediff (MONTH,AgentStart, getdate()), AgentStart) > getdate()
THEN datediff(MONTH, AgentStart, ...