What is the error here?

|
Swapnil 2022-07-03 14:51:02
Sandip Londhe 2022-07-03 08:53:46
Swapnil can you tell some real time situation where we can use store procedures

When requirement is to perform set of SQL operation with dynamic parameters values.
Also SP is resuable i.e create once and use as many number of time

Swapnil 2022-07-03 14:51:52
Sandip Londhe 2022-07-03 13:21:06
Find the number of apartments per nationality that are owned by people under 30 years old.
Output the nationality along with the number of apartments.
Sort records by the apartments count in descending order.

Provide sample data and expected output

Sandip Londhe 2022-07-03 14:52:39
Swapnil 2022-07-03 14:51:52
Provide sample data and expected output

Okay wait

Amrendra_Singh1 2022-07-03 15:42:51
I m looking for MYSQL DBA TRAINING. If anyone provides plz msg me
Muraliy7 2022-07-03 18:10:40
Amrendra_Singh1 2022-07-03 15:42:51
I m looking for MYSQL DBA TRAINING. If anyone provides plz msg me

Call me

Dude 2022-07-04 07:09:32
Is it not recommended to restore mysql schema when migrating data from version 5.7 to 8?
Liran 2022-07-04 08:48:14
I need to sum every hour all the items number of units our store sold from our Orders table. i thought making a side table to have this data (item_id, units_sold).
how should i implement the job?
Swapnil 2022-07-04 09:40:05
Liran 2022-07-04 08:48:14
I need to sum every hour all the items number of units our store sold from our Orders table. i thought making a side table to have this data (item_id, units_sold).
how should i implement the job?

Is the database on prem or cloud ?

Liran 2022-07-04 09:42:36
Swapnil 2022-07-04 09:40:05
Is the database on prem or cloud ?

cloud (GCP)

Swapnil 2022-07-04 10:01:00
Liran 2022-07-04 09:42:36
cloud (GCP)

Simply create a stored procedure that will take records from last 1 hr and insert it into other table.
Create a job for same that will be executed every hr

Liran 2022-07-04 10:06:13
Swapnil 2022-07-04 10:01:00
Simply create a stored procedure that will take records from last 1 hr and insert it into other table.
Create a job for same that will be executed every hr

How can I do this so if the item_id already exist in the sum_table it will add more units to it and won’t try to insert a new record ?

Liran 2022-07-04 10:33:37
like if my side table already have this data:
item_id units_sold
1 5
2 6

and now in the Orders table in the past hour i have those:

item_id user_id
1 746473
2 345344
3 2342342

I want that my new side table will be this:
item_id units_sold
1 6
2 7
3 1

how can i do that?

Swapnil 2022-07-04 11:23:20
Liran 2022-07-04 10:33:37
like if my side table already have this data:
item_id units_sold
1 5
2 6

and now in the Orders table in the past hour i have those:

item_id user_id
1 746473
2 345344
3 2342342

I want that my new side table will be this:
item_id units_sold
1 6
2 7
3 1

how can i do that?

Which database is this ?

Liran 2022-07-04 11:23:58
Swapnil 2022-07-04 11:23:20
Which database is this ?

mysql

Swapnil 2022-07-04 11:24:29
There is something called as on duplicates
Swapnil 2022-07-04 11:25:18
but if not you can make use of
if exists clause to check if item_id already exists. If yes then update the count.
If not then insert
Liran 2022-07-04 11:26:49
Swapnil 2022-07-04 11:25:18
but if not you can make use of
if exists clause to check if item_id already exists. If yes then update the count.
If not then insert

oh i see, so I do this as part of the stored procedure. do you happen to have such example? if exists update else insert?

Swapnil 2022-07-04 12:11:42
Liran 2022-07-04 11:26:49
oh i see, so I do this as part of the stored procedure. do you happen to have such example? if exists update else insert?

Kindly find below high level code syntax for same

IF (SELECT 1 = 1 FROM Tablename WHERE created_on >= last 1 hour) THEN
BEGIN
WITH cte_update as
(SELECT ID, count(*) as cnt
FROM Tablename
WHERE created_on is >= last 1 hour
GROUP BY ID
)
UPDATE tablename set count = tablename.count cte_update.cnt
FROM cte_update
WHERE tablename.ID = cte_update.ID;
END;
ELSE
BEGIN
INSERT INTO Table
SELECT ID, count(*) as cnt
FROM Tablename
WHERE created_on is >= last 1 hour
GROUP BY ID ;
END;
END IF;

NILESH SHARMA 2022-07-04 14:21:29
hey everyone can anyone help me with this
NILESH SHARMA 2022-07-04 14:21:35
mysql_en-22422.jpg

Swapnil 2022-07-04 14:31:48
NILESH SHARMA 2022-07-04 14:21:35

Is it mysql database ?

NILESH SHARMA 2022-07-04 14:32:20
may be no
NILESH SHARMA 2022-07-04 14:32:33
we are been said to work in mssql
NILESH SHARMA 2022-07-04 14:33:24
i am a learned thats y got to know about your group on the google so joined this if anyone can help me with this
Swapnil 2022-07-04 14:40:02
NILESH SHARMA 2022-07-04 14:32:33
we are been said to work in mssql

https://stackoverflow.com/questions/10581772/how-to-split-a-comma-separated-value-to-columns

How to split a comma-separated value to columnsStack Overflow
I have a table like this

Value String
——————-
1 Cleo, Smith
I want to separate the comma delimited string into two columns

Value Name Surname
——————-
1 Cleo

Sonali 2022-07-04 14:41:52
Sonali 2022-07-01 21:00:36
a. Write function that takes the customernumber as input and returns the purchase_status based on the following criteria.[table:Payments]

If the total purchase amount for the customer is <25000 status=silver, amount between 25000 and 50000 status= Gold, amount>50000 status= Platinum.

b. Write a query that displays customernumber, customername and purchase_status from customers table.

mysql_en-22428.jpg
Pls help ..this is not working

Swapnil 2022-07-04 14:52:52
Sonali 2022-07-04 14:41:52
Pls help ..this is not working

What is the error here ?

Sonali 2022-07-04 15:00:28
Swapnil 2022-07-04 14:52:52
What is the error here ?

mysql_en-22430.jpg
Unknown column

Swapnil 2022-07-04 15:04:43
Sonali 2022-07-04 14:41:52
Pls help ..this is not working

First of all return type of function should be varchar not int

Swapnil 2022-07-04 15:05:51
Also you have not mentioned
return(purchase_status) in the end
Sonali 2022-07-04 15:10:03
Swapnil 2022-07-04 15:05:51
Also you have not mentioned
return(purchase_status) in the end

Yes its there..I have mentioned it after end if statement.

Swapnil 2022-07-04 17:09:28
Sonali 2022-07-04 15:10:03
Yes its there..I have mentioned it after end if statement.

paste the code in pastebin and share the link
Image or screenshot wont help

RakeshPardeshi 2022-07-04 18:55:34
Hi All, I have one sql database design and implementation assignment. Please dm me if you are interested to work on this assignment
private_String 2022-07-04 18:56:30
what about this?
adiamrit 2022-07-04 19:00:45
RakeshPardeshi 2022-07-04 18:55:34
Hi All, I have one sql database design and implementation assignment. Please dm me if you are interested to work on this assignment

yes I am interested

|